【问题标题】:Make EHCache expire elements which have not been accessed in a specific way使 EHCache 以特定方式使未被访问的元素过期
【发布时间】:2011-05-23 21:27:51
【问题描述】:

我正在尝试让 EHCache 将缓存元素标记为过期,如果它们在指定的时间内没有以特定方式被访问。

我有一个自动缓存刷新器,它应该刷新缓存中的元素而不更新上次访问时间。它定期运行。但是,如果用户通过应用程序从缓存中请求某些内容,则应更新上次访问时间。在用户不活动一周后,元素应过期并从缓存中删除。

EHCache 是否已经存在可以解决此类问题的任何东西?我看到了putQuietgetQuiet 方法,但我没有看到任何明确提及它们没有更新上次访问时间。另外,timeToLiveSecondstimeToIdleSeconds 参数之间有什么真正的区别吗?

谢谢, 迈克

【问题讨论】:

    标签: java caching ehcache


    【解决方案1】:
     timeToIdleSeconds:
    Sets the time to idle for an element before it expires.
    i.e. The maximum amount of time between accesses before an element expires
    Is only used if the element is not eternal.
    Optional attribute. A value of 0 means that an Element can idle for infinity.
    The default value is 0.
    
    timeToLiveSeconds:
    Sets the time to live for an element before it expires.
    i.e. The maximum time between creation time and when an element expires.
    Is only used if the element is not eternal.
    Optional attribute. A value of 0 means that and Element can live for infinity.
    The default value is 0.
    

    对于其他属性,请参阅 ehcache 包附带的 ehcache.xml。您可以使用带有参数的Cache construtor 实例化您的缓存,然后缓存将自行管理它

    【讨论】:

      猜你喜欢
      • 2016-10-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-09
      • 2012-05-03
      相关资源
      最近更新 更多