Integrations - EHCache |
rate-12982-33158
| Article Rating? |
|
|
|
| Product Type |
Caching |
| Versions Supported |
1.2.4 , 1.3 |
| Module Status |
- Forge download
- Included with Terracotta 2.5.4 and earlier |
| Module Availability - Released (latest) |
See Terracotta Forge Releases |
| Module Availability - SNAPSHOT (latest) |
See Terracotta Forge Snapshots |
| Download with Kit |
Not Included |
Introduction
The Ehcache Terracotta integration module (TIM) provides a fragment of Terracotta configuration to instrument certain classes under the net.sf.ehcache package. Additionally, relevant EHCache internals have been re-implemented to benefit from Terracotta features and optimizations such as:
- Fine-grained read and write locks
- An optimized eviction policy
- Increased scalability
- Cluster-wide cache coherency
These features and optimizations take effect automatically after EHCache is integrated with Terracotta DSO. However, due to an overlap between EHCache and Terracotta DSO features, the following EHCache behaviors are not directly supported:
- Standard eviction policies:
The standard LRU, LFU and FIFO cache eviction policies are automatically replaced by a time-based eviction policy that is optimized for Terracotta DSO.
The following standard Ehcache parameters are used:
- diskExpiryThreadIntervalSeconds: The number of seconds between eviction runs
- timeToIdleSeconds: The time to idle for an element before it expires
- timeToLiveSeconds: The time to live for an element before it expires
- Notifications:
To reduce cluster-wide locks, cache notifications are not supported. Since this is mainly used in EHCache's traditional distribution strategy, there's little use for these when Terracotta is active. In case you do require notifications for other purposes, please contact our support team
.
- Disk storage:
The Terracotta DSO persistent mode
is more flexible than the EHCache persistent mode since it doesn't require cache keys and values to be serializable. None of the standard EHCache disk storage features are available when Terracotta is used.
- 'eternal' cache parameter:
The eternal parameter currently isn't available for cache configuration. However, by setting the timeToIdleSeconds and timeToLiveSeconds parameters to 0, the same characteristics can be obtained.
- 'maxElementsInCache' cache parameter:
This parameter is currently not supported.
Dependencies
Previous versions of the module required the use of org.apache.commons.collections.LRUMap from Apache Commons Collections. The current EHCache TIM does not have this requirement.
With EHCache 1.3, jsr107cache.jar (version 1.0) must be available on the application classpath.
Implementation
To enable clustering with EHCache, add the EHCache TIM to tc-config.xml:
<modules>
<module name="tim-ehcache-<EHCache_version>" version="<module_version>"/>
</modules>
For example, if you use the module tim-ehcache-1.2.4-1.1.1, add the following snippet to tc-config.xml:
<modules>
<module name="tim-ehcache-1.2.4" version="1.1.1"/>
</modules>
 |
The name of the older modules included with Terracotta kits followed the format clustered-ehcache-<EHCache_version>-<module_version>. |
For a step-by-step overview on implementing Terracotta DSO with EHCache, see the EHCache Getting Starting Guide.
Known Issues
Client applications should declare a CacheManager field and mark it as root.
If the following field is declared in the application Java code:
package foo.bar.baz;
import net.sf.ehcache.CacheManager;
public class FooBar {
protected CacheManager manager = new CacheManager();
}
then the following entry must appear in tc-config.xml:
<roots>
<root>
<field-name>foo.bar.baz.FooBar.manager</field-name>
</root>
</roots>
If the client application uses the singleton methods CacheManager.getInstance() or CacheManager.create() to instantiate a CacheManager, then there is no need to declare the field foo.bar.baz.FooBar.manager a root because the EHCache config-bundle declares that automatically.