Ehcache (2.9.x)-API Developer Guide, Key Classes and Methods

Source: Internet
Author: User

About the Key Classes

Ehcache consists of a CacheManager, which manages logical data sets represented as Caches. A Cache object contains Elements, which is essentially name-value pairs. You can use the cache objects to hold any kind of data so you want to keep in memory, not just data, the want to Cache.

Caches is physically implemented, either in-memory or on disk. The logical representations of these components is actualized mostly through the following classes:

    • CacheManager
    • Cache
    • Element

These classes form the core of the Ehcache API. The methods provided by these classes is largely responsible for providing programmatic access to a cache or In-memory da TA store.

CacheManager

The CacheManager class is used to manage caches. Creation of, access to, and removal of caches are controlled by a named CacheManager.

CacheManager Creation Modes

cachemanager supports, creation Modes:singleton and instance. The types can exist in the same JVM. However, multiple cachemanagers with the same name is not allowed-exist in the same JVM. CacheManager () constructors creating Non-singleton cachemanagers can violate this rule, causing a nullpointerexcep tion. If your code might create multiple cachemanagers of the same name in the same JVM, avoid this error by using the static Ca Chemanager.create () methods, which always return the named (or default unnamed) CacheManager if it already exists Jvm. If the named (or default unnamed) CacheManager does not exist, the cachemanager.create () methods create it.

For singletons, calling Cachemanager.create (...) returns the existing singleton CacheManager with the configured name (if It exists) or creates the singleton based on the passed-in configuration.

To work from a configuration, use the Cachemanager.newinstance (...) method, which parses the passed-in configuration to Eith Er get the existing named CacheManager or create that cachemanager if it doesn ' t exist.

To review, the behavior of the CacheManager creation methodsare as follows:

    • cachemanager.newinstance (configuration) –create a new CacheManager or return the existing one named in the configuration.
    • cachemanager.create () –create a new Singleton CacheManager with default configuration, or return the existing singleton. This is the same as Cachemanager.getinstance ().
    • cachemanager.create (Configuration Configuration) –create a singleton CacheManager with the passed-in configuration, or return the existing singleton .
    • new CacheManager (Configuration configuration) –create A new CacheManager, or throw an exception if the CacheManager named in the configuration already exists O R if the parameter (configuration) is null.

Note that in Instance-mode (Non-singleton), where multiple cachemanagers can is created and used concurrently in the same JVM, each of the CacheManager requires its own configuration.

If the Caches under management use the disk store, the Disk-store path specified in each CacheManager configuration sh Ould be unique. This was because when a new CacheManager is created, a check was made to ensure so no other cachemanagers be using the SA Me disk-store path. Depending upon your persistence strategy, Ehcache would automatically resolve a Disk-store path conflict, or it'll let yo U know that must explicitly configure the Disk-store path.

If Managed caches use only the memory store, there is no special considerations.  

Cache

a cache is a thread-safe logical representation of a set of data elements, analogous to a cache region in many caching Systems. Once a reference to a cache are obtained (through a cachemanager), logical actions can be performed. The physical implementation of these actions are relegated to the stores. For more information on the stores, see "Configuring Storage Tiers" in the Configuration Guide for Ehcache.

Caches is instantiated from configuration or programmatically using one of the Cache () constructors. Certain cache characteristics, such as Automatic Resource Control (ARC)-related sizing, and pinning, must be set using con Figuration.

Cache methods can used to get information on the cache (for example, Getcachemanager (), isnodebulkloadenabled (), and Issearchable ()), or perform certain cache-wide operations (for example, flush, load, initialize, and Dispose).

The methods provided in the cache class also allow you to work with the cache elements (for example, get, set, remove, and rep Lace) as well as get information on the them (for example, IsExpired, ispinned).

Element

An element was an atomic entry in a cache. It has a key, a value, and a record of accesses. Elements is put into and removed from caches. They can also expire and be removed by the cache, depending on the cache settings.

There is a API for Objects in addition to the one for Serializable. non-serializable Objects can is stored only in heap. If an attempt was made to persist them, they was discarded with a debug-level log message but no error.

The APIs is identical except for the return methods from Element:getkeyvalue () and Getobjectvalue () is used by the Obje CT API in place of GetKey () and GetValue ().

Ehcache (2.9.x)-API Developer Guide, Key Classes and Methods

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.