开发者

Is it possible to limit the size of Hibernate second-level-cache for a specific entity?

开发者 https://www.devze.com 2023-02-10 02:57 出处:网络
I have a scenario where Hibernate second-level-cache is enabled and I\'d like to cache an entity for which 1开发者_如何学JAVA000 instances are created every day and retained for 8 years but the querie

I have a scenario where Hibernate second-level-cache is enabled and I'd like to cache an entity for which 1开发者_如何学JAVA000 instances are created every day and retained for 8 years but the queries only deal with the most recent 2 days. I would like to avoid having to create a history table because then for the rare cases for historical lookup, the code is dependent on the date.

Is it possible in Hibernate, with Infinispan as the Level-2 provider, to configure very specifically, a particular cache with specific attributes (eviction policy, size, etc.) that Hibernate should use for entity Foo?


Yes. In Hibernate, you can have N cache "regions", which can have different configurations and can be specific to some entities. The configuration itself is dependent on the provider (Infinispan, in your case). See this document for more details on Infinispan configuration:

http://community.jboss.org/wiki/usinginfinispanasjpahibernatesecondlevelcacheprovider#Advanced_Configuration

Look at the examples on how to override the defaults for an entity/collection. There, you can set the eviction strategy, the lifespan and the number of entities to keep in the cache.

0

精彩评论

暂无评论...
验证码 换一张
取 消