【发布时间】:2016-04-04 14:16:23
【问题描述】:
我使用angular-cache 和localStorage 将文章本地保存在html5 中。 documentation states有一个选项叫“容量”:
容量
缓存可以容纳的最大项目数。添加更多项目 比容量会导致缓存像 LRU 缓存一样运行, 删除最近最少使用的项目以保持容量不足。 默认值:Number.MAX_VALUE。
由于我最多只想存储 20 篇文章,所以我这样配置:
CacheFactory('articleCache', {
storagePrefix : 'my.news.',
capacity : 20,
storageMode: 'localStorage'
});
当我想获取数据时,我只需这样做:
$http.get(url, {cache: CacheFactory.get('articleCache')});
使用我的应用程序一段时间后,我突然注意到它停止工作,因为达到了 localStorage 限制配额。当我打印console.log(localStorage) 时,我看到localStorage 中存储的不仅仅是20 篇文章。因此,出于某种原因,尽管文档承诺相反,但 angular-cache 不会删除最旧的项目。
那么,我做错了什么还是 angular-cache 中存在错误?
【问题讨论】:
标签: javascript angularjs html caching