gpt4 book ai didi

javascript - 为什么 Angular-Cache 忽略容量配置?

转载 作者:行者123 更新时间:2023-11-28 06:33:05 27 4
gpt4 key购买 nike

我使用angular-cache使用localStorage将文章保存在html5本地。 documentation states有一个名为“容量”的选项:

capacity

Maximum number of items a cache can hold. Adding more items than the capacity will cause the cache to operate like an LRU cache, removing the least recently used items to stay under capacity. Default: Number.MAX_VALUE.

由于我只想存储最多 20 篇文章,所以我这样配置:

CacheFactory('articleCache', {
storagePrefix : 'my.news.',
capacity : 20,
storageMode: 'localStorage'
});

当我想获取数据时,我只需这样做:

$http.get(url, {cache: CacheFactory.get('articleCache')});

使用我的应用程序一段时间后,我突然注意到它停止工作,因为已达到本地存储限制配额。当我打印 console.log(localStorage) 时,我发现 localStorage 中存储的文章数量远不止 20 篇。因此,由于某种原因, Angular 缓存不会删除最旧的项目,尽管文档 promise 相反。

那么,我做错了什么或者 Angular 缓存中有错误吗?

最佳答案

好的,这是 Angular-Cache 中的一个错误,现已在版本 4.4.3 中修复,请参阅 https://github.com/jmdobry/angular-cache/issues/210

安装更新后,我的应用程序按预期运行。

关于javascript - 为什么 Angular-Cache 忽略容量配置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34532348/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com