A sleeping cached request is not updated when a new record is inserted

We have a cluster of EHCache, hibernate and Mysql.

Everything works almost fine. Search criteria is cached, and when records change on other cluster members, cached queries are instantly updated on other servers.

however, my problem is that new entries are inserted. The cached requests in this table are unaware of this until the expiration of the cached request.

I probably missed something in my EHcache.xml configuration, but I have no idea what it could be.

Any ideas?

EHCache.xml follows:

`

<!--<diskStore path="java.io.tmpdir"/>--> <!-- means for cache replication --> <cacheManagerPeerProviderFactory class="net.sf.ehcache.distribution.jgroups.JGroupsCacheManagerPeerProviderFactory" properties="connect= TCP(bind_port=10700): S3_PING(...): MERGE2(max_interval=30000;min_interval=10000): FD_SOCK(start_port=0): FD(timeout=3000;max_tries=3): VERIFY_SUSPECT(timeout=1500): BARRIER(): pbcast.NAKACK(use_mcast_xmit=false;gc_lag=0;retransmit_timeout=300,600,1200,2400,4800;discard_delivered_msgs=true): UNICAST(timeout=300,600,1200): pbcast.STABLE(stability_delay=1000;desired_avg_gossip=50000;max_bytes=400K): pbcast.GMS(print_local_addr=true;join_timeout=300;view_bundling=true): FC(max_credits=2M;min_threshold=0.10): FRAG2(frag_size=60K): pbcast.STREAMING_STATE_TRANSFER()" propertySeparator="::" /> <!-- default query cache to be used for all queries without an explicit cache --> <cache name="org.hibernate.cache.StandardQueryCache" maxElementsInMemory="100" eternal="false" timeToLiveSeconds="600" overflowToDisk="false" statistics="true"> <cacheEventListenerFactory class="net.sf.ehcache.distribution.jgroups.JGroupsCacheReplicatorFactory" properties="replicateAsynchronously=true, replicatePuts=true, replicateUpdates=true, replicateUpdatesViaCopy=false, replicateRemovals=true" /> </cache> <!-- timestamps of particular last update time to tables --> <cache name="org.hibernate.cache.UpdateTimestampsCache" maxElementsInMemory="5000" eternal="true" overflowToDisk="false" statistics="true"> <cacheEventListenerFactory class="net.sf.ehcache.distribution.jgroups.JGroupsCacheReplicatorFactory" properties="replicateAsynchronously=true, replicatePuts=true, replicateUpdates=true, replicateUpdatesViaCopy=false, replicateRemovals=true" /> </cache> <!-- default cache to use for all cacheable entities without an explicit cache --> <defaultCache maxElementsInMemory="10000" eternal="false" timeToIdleSeconds="600" timeToLiveSeconds="600" overflowToDisk="false" maxElementsOnDisk="10000000" diskPersistent="false" diskExpiryThreadIntervalSeconds="600" memoryStoreEvictionPolicy="LRU" statistics="true"> <cacheEventListenerFactory class="net.sf.ehcache.distribution.jgroups.JGroupsCacheReplicatorFactory" properties="replicateAsynchronously=true, replicatePuts=true, replicateUpdates=true, replicateUpdatesViaCopy=false, replicateRemovals=true" /> </defaultCache> 

`

+4
source share
2 answers

I am afraid it is too late for the author, but I thought that my answer might be useful to someone else with the same problem.

You must remember how StandardQueryCache and UpdateTimestampsCache . When the query cache is checked for a query, the time during which the query was cached is compared with the timestamps of the last update of all tables in the query. If any tables were updated after query caching, the caching result will be discarded and the database will be used instead. The timestamps of the last update for each table are stored in UpdateTimestampsCache .

In the above configuration, the values ​​from UpdateTimestampsCache not copied to other members of the cluster, so Hibernate looks at the old timestamps and considers that the cached request is relevant. As a result, newly inserted records are neglected. To fix this, simply set the replicateUpdatesViaCopy parameter UpdateTimestampsCache to true.

+4
source

Link: Ehcache Configuration

Note that the perpetual attribute, when set to true, overrides timeToLive and timeToIdle so that there is no expiration.

You have set the value 1 of the eternal attribute true. Maybe you can try setting it to false and see if that helps?

0
source

All Articles