[英]ehcache keySet timed out when using getKeysWithExpiryCheck() method
我正在使用ehcache来控制用户会话,我偶尔会在用户登录时在日志中看到此错误。
net.sf.ehcache.constructs.nonstop.NonStopCacheException: keySet timed out
at net.sf.ehcache.constructs.nonstop.concurrency.NonStopCacheKeySet$NonStopCacheKeySetIterator$1.performClusterOperationTimedOut(NonStopCacheKeySet.java:103)
at net.sf.ehcache.constructs.nonstop.concurrency.NonStopCacheKeySet$NonStopCacheKeySetIterator$1.performClusterOperationTimedOut(NonStopCacheKeySet.java:96)
at net.sf.ehcache.constructs.nonstop.store.ExecutorServiceStore.executeClusterOperation(ExecutorServiceStore.java:1187)
at net.sf.ehcache.constructs.nonstop.store.NonstopStoreImpl.executeClusterOperation(NonstopStoreImpl.java:704)
at net.sf.ehcache.constructs.nonstop.concurrency.NonStopCacheKeySet$NonStopCacheKeySetIterator.<init>(NonStopCacheKeySet.java:96)
at net.sf.ehcache.constructs.nonstop.concurrency.NonStopCacheKeySet.iterator(NonStopCacheKeySet.java:56)
at net.sf.ehcache.Cache.getKeysWithExpiryCheck(v.java:1906)
...
官方ehcache doucmentation说:“考虑您的使用是否需要检查过期的密钥。因为这种方法需要很长时间,具体取决于缓存设置,......”。
所以我不确定ecache.xml中的什么超时会增加以阻止此错误,即使20000毫秒似乎对我来说已经足够了,因为文档还提到所花费的时间大约是每1000个条目200毫秒。
这是使用过的ehcache.xml。
<?xml version="1.0" encoding="UTF-8"?>
<ehcache name="RelianceCache" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="ehcache.xsd">
<cache name="READ_USERS_CACHE" maxElementsInMemory="0" eternal="true" overflowToDisk="false">
<terracotta clustered="true" valueMode="serialization" consistency="strong">
<nonstop immediateTimeout="false" timeoutMillis="20000">
<timeoutBehavior type="exception" />
</nonstop>
</terracotta>
</cache>
<terracottaConfig url="TSA_SERVERS:TSA_PORT" rejoin="true" />
</ehcache>
编辑:请参阅NonStopCacheKeySet实现 ,在NonStopCacheKeySetIterator
方法中抛出错误。
增加超时不会解决问题。 100个参赛作品的20秒非常长。
如果从应用程序逻辑的角度来看是合适的,我会考虑将timeoutBehavior改为timeoutBehavior="localReadsAndExceptionOnWrite"
。 请注意, localCacheEnabled
属性必须为TRUE,这是默认值。
...
<terracotta clustered="true" localCacheEnabled="true" valueMode="serialization" consistency="strong">
<nonstop immediateTimeout="false" timeoutMillis="20000">
<timeoutBehavior type="localReadsAndExceptionOnWrite" />
</nonstop>
</terracotta>
...
另一种解决方案可能是将一致性更改为默认值consistency ="eventual"
。 这很可能解决问题,但可能导致缓存返回的临时陈旧数据。
正如文档所述“考虑您的使用是否需要检查过期密钥......”。 是否可以调整应用程序逻辑以使用Cache.getKey()而不是通过键列表进行迭代?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.