【问题标题】:Why does angular-cache ignore capacity configuration?为什么 angular-cache 忽略容量配置?
【发布时间】: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


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-02-03
      • 2012-06-26
      • 2020-01-09
      • 1970-01-01
      • 2022-11-03
      • 2016-11-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多