Caching
Improve your database performance with secondary caching in Hibernate ORM.
Secondary Cache
A secondary cache provider is a class which manages a level of caching that is secondary to Hibernate's main caching context - the Hibernate session. A secondary cache enables longer-running cache contexts, more fine-grained control over cache busting, and other performance-related benefits.
The only setting necessary to enable secondary caching is the secondaryCacheEnabled
setting:
To configure the caching, specify the path to an XML cache configuration file in cacheConfig
:
This ehcache.xml
cache configuration then should look something like this:
Configure Each Entity Cache
Notice how our ehcache.xml
defines a default cache configuration?
We highly recommend adding a cache configuration for each cacheable entity. This will help you optimize caching, and will silence error logs like the below:
Here's a quick example. Say we have an Autos.cfc
persistent component with caching enabled:
For this entity, we'll want to create a <cache></cache>
entry with a name
attribute that matches the entity name OR our cacheName
component annotation:
Alternate Cache Providers Are Unsupported
While there is a cacheProvider
setting, only EHCache (currently) is supported as a secondary cache provider.
Thus, any usage of cacheProvider
other than "ehcache"
will be ignored.
Last updated