Ehcache 2.10.5 | About Ehcache | Storage Options | Storage Tiers
 
Storage Tiers
You can divide a cache or in-memory data set across the following storage areas, referred to as tiers:
*MemoryStore – On-heap memory used to hold cache elements. This tier is subject to Java garbage collection.
*OffHeapStore – Provides overflow capacity to the MemoryStore. Limited in size only by available RAM. Not subject to Java garbage collection (GC). Available only with Terracotta BigMemory products.
*DiskStore – Backs up in-memory cache elements and provides overflow capacity to the other tiers.
MemoryStore
The memory store is always enabled and exists in heap memory. It has the following characteristics:
*It accepts all data, whether serializable or not.
*It is the fastest storage option.
*Is thread safe for use by multiple concurrent threads.
If you use OffHeapStore (available with the BigMemory products only), MemoryStore holds a copy of the hottest subset of data from the OffHeapStore.
All caches specify their maximum in-memory size, in terms of the number of elements, at configuration time.
When an element is added to a cache and it goes beyond its maximum memory size, an existing element is either deleted, if overflow is not enabled, or evaluated for spooling to another tier, if overflow is enabled.
If overflow is enabled, a check for expiry is carried out. If it is expired it is deleted; if not it is spooled.
For information about sizing and configuring the MemoryStore, see "Configuring Memory Store" in the Ehcache Configuration Guide.
OffHeapStore
The OffHeapStore extends a cache to memory outside the of the Java heap. This store, which is not subject to Java garbage collection (GC), is limited only by the amount of RAM available. Using OffHeapStore, you can create extremely large local caches. OffHeapStore is only available with the Terracotta BigMemory products.
Because off-heap data is stored in bytes, only data that is Serializable is suitable for the OffHeapStore. Any non serializable data overflowing to the OffHeapMemoryStore is simply removed, and a WARNING level log message is emitted.
Since serialization and deserialization take place on putting and getting from the off-heap store, it is theoretically slower than the MemoryStore. This difference, however, is mitigated when garbage collection associated with larger heaps is taken into account.
For the best performance, you should allocate to a cache as much heap memory as possible without triggering GC pauses. Then, use the OffHeapStore to hold the data that cannot fit in heap (without causing GC pauses).
For information about sizing and configuring OffHeapStore, see "Configuring OffHeapStore" in the Configuration Guide for your BigMemory product.
DiskStore
The DiskStore provides a thread-safe disk-spooling facility that can be used for either additional storage or persisting data through system restarts.
Note: The DiskStore tier is available only for local (standalone) instances of cache. When you use a distributed cache (available only in BigMemory Max), a Terracotta Server Array is used instead of a disk tier.
Only data that is Serializable can be placed in the DiskStore. Writes to and from the disk use ObjectInputStream and the Java serialization mechanism. Any non-serializable data overflowing to the disk store is removed and a NotSerializableException is thrown. Be aware that serialization speed is affected by the size of the objects being serialized and their type. For example, it has been shown that:
*The serialization time for a Java object consisting of a large Map of String arrays was 126ms, where the serialized size was 349,225 bytes.
*The serialization time for a byte[] was 7ms, where the serialized size was 310,232 bytes.
Byte arrays are 20 times faster to serialize, making them a better choice for increasing disk-store performance.
Configuring a disk store is optional. If all caches use only memory and off-heap stores, then there is no need to configure a disk store. This simplifies configuration, and uses fewer threads.
For more information about configuring and sizing the DiskStore, see the "Persistence and Restartability" section in the Ehcache Configuration Guide.

Copyright © 2010-2018 | Software AG, Darmstadt, Germany and/or Software AG USA, Inc., Reston, VA, USA, and/or its subsidiaries and/or its affiliates and/or their licensors.
Innovation Release