cache update when using Hibernate query cache

142 Views Asked by At

I am using hibernate query cache mechanism to store query results in cache memory and will be retrieved from cache.But if any update in the table, it should be updated in the cache when next query hits the table. Here i am using same query like select * from table. when i tried this,i am getting same information even table is upted.

1

There are 1 best solutions below

2
On

If the objects are not updated through hibernate, hibernate would not know about them and hence the query cache is not updated. If you are updated through hibernate but on a different application server then you need to use a distributed cache that spans across a cluster. for e.g. JBoss Tree Cache.

If you can't control the updates from happening externally but you know the time/period when the occur you could keep the TTL of this query cache shorter than that so that hibernate evicts the entries from the cache before they are updated from outside.