angular.js - angularjs $cacheFactory capacity 怎么理解
过去多啦不再A梦
过去多啦不再A梦 2017-05-15 17:12:19
0
2
459


怎么理解图中的话,最好有demo

自己写了个demo超过了限制的capacity:3但是每次缓存cache.info()打印出来的size都一样。另外$cacheFactory(key,[option])中的key只能是一个字符串吗,如何一次定义多个缓存对象

过去多啦不再A梦
过去多啦不再A梦

reply all (2)
大家讲道理

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:

    var lru = $cacheFactory('lru', {capacity: 20}); // $http请求 $http.get('/api/users.json', {cache: lru}).then(function(data){});

    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:

    angular.module('myApp', []) .config(function($httpProvider, $cacheFactory) { $httpProvider.defaults.cache = $cacheFactory('lru', { capacity: 20 }); });
      Latest Downloads
      More>
      Web Effects
      Website Source Code
      Website Materials
      Front End Template
      About us Disclaimer Sitemap
      php.cn:Public welfare online PHP training,Help PHP learners grow quickly!