gpt4 book ai didi

java - Ehcache 正在为磁盘持久性创建不必要的时间戳目录

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:36:30 25 4
gpt4 key购买 nike

我想使用 Ehcache 的磁盘持久性,它能够在重启之间保留数据。我的配置如下所示:

<ehcache>

<diskStore path="/tmp/blah"/>

<defaultCache
eternal="true"
maxElementsInMemory="500"
overflowToDisk="false"
memoryStoreEvictionPolicy="LRU"
statistics="true"/>

<cache
name="myCache"
eternal="true"
maxElementsInMemory="10"
maxElementsOnDisk="10000"
overflowToDisk="true"
diskPersistent="true"
memoryStoreEvictionPolicy="LRU"
statistics="true"/>

</ehcache>

使用上面的,我注意到不仅/tmp/blah/myCache.data被创建但也 /tmp/blah/ehcache_auto_created_<timestamp>/myCache.data .持久化数据进入带时间戳的文件夹,问题是缓存数据无法在重启后重复使用。此外,我认为一般情况下根本没有时间戳目录。

经过几个小时的调试,我发现这来自CacheManager.detectAndFixDiskStorePathConflict方法。此方法遍历 ALL_CACHE_MANAGERS并检查是否diskStorePath跨越匹配。结果为真(尽管在我的例子中,CacheManager 中只有一个 ALL_CACHE_MANAGERS)和 diskStorePath被笨拙地重命名。

日志警告建议考虑单例CacheManager .我对缓存管理器的了解并不深,但我无意使用多个(尤其是在不同设置下)。我访问 net.sf.ehcache.CacheManager 的唯一途径通过CacheManager.getInstance() ,如文档中所建议的那样。

任何人都可以在这里阐明一些问题吗?这是错误吗?

我正在使用 Ehcache 版本 2.4.4。

完整堆栈跟踪:

main@1, prio=5, in group 'main', status: 'RUNNING'
at net.sf.ehcache.CacheManager.detectAndFixDiskStorePathConflict(CacheManager.java:612)
at net.sf.ehcache.CacheManager.configure(CacheManager.java:586)
at net.sf.ehcache.CacheManager.init(CacheManager.java:359)
at net.sf.ehcache.CacheManager.<init>(CacheManager.java:228)
at net.sf.ehcache.hibernate.EhCacheRegionFactory.start(EhCacheRegionFactory.java:79)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:250)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1385)
...

提前致谢。

最佳答案

问题是因为我一直在我的 hibernate 绑定(bind)中使用 EhCacheRegionFactory(特定缓存与 Hibernate 完全无关,但在同一文件中定义)。

我已切换到 SingletonEhCacheRegionFactory,问题消失了。

关于java - Ehcache 正在为磁盘持久性创建不必要的时间戳目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7308868/

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