capacity is equivalent to specifying a maximum usable capacity for the cache. For a simple example, if you have 3 buckets (capacity=3) and you fill the first bucket of water (put), then it still has 3 buckets. Fill another bucket of water until the fourth bucket of water is filled. Since there are only 3 buckets, it is obvious that this bucket of water cannot be filled. What should I do? Dump the first bucket of water and use this bucket to hold the fourth bucket of water (cache strategy: LRU) You can take a look at the implementation of $cacheFatory, you should have a deeper understanding
capacity is equivalent to specifying a maximum usable capacity for the cache.
For a simple example, if you have 3 buckets (capacity=3) and you fill the first bucket of water (put), then it still has 3 buckets. Fill another bucket of water until the fourth bucket of water is filled. Since there are only 3 buckets, it is obvious that this bucket of water cannot be filled. What should I do? Dump the first bucket of water and use this bucket to hold the fourth bucket of water (cache strategy: LRU)
You can take a look at the implementation of $cacheFatory, you should have a deeper understanding
capacity involves LRU (Least Recenlty Used, least recently used) cache, such as:
Now, the latest 20 requests will be cached. The 21st request will cause LRU to remove the older request from the cache.
We can also set a default cache for all $http requests through the application's .config() function, that is, the configuration phase: