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

4.2k views Asked by At

I have a scenario where Hibernate second-level-cache is enabled and I'd like to cache an entity for which 1000 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?

1

There are 1 answers

0
jpkroehling On BEST ANSWER

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.