Setting up the Cache Provider

Wanghy-Cache provides a common interface that contains and centralizes the interactions with the underlying cache provider. Each facade must implement the interface org.wanghy.cache.provider.CacheProviderFacade or subclass the template org.wanghy.cache.provider.AbstractCacheProviderFacadeImpl.

All the provided facades have these common properties:

  1. cacheManager (required).

    A cache manager administrates the cache.

    In general, a cache manager should be able to:

    • Store objects in the cache.
    • Retrieve objects from the cache.
    • Flush or invalidate the cache.

    The cache manager can be replaced by a factory that creates a singleton instance of the cache manager. Such factory allows custom configuration of the cache manager (depending on the cache provider) and ensures that the Spring container shuts down the cache manager when the factory is destroyed by the BeanFactory.

    Wanghy-Cache supplies factories for the supported cache providers. (with the exception of EHCache, which is provided by the Spring Framework). Each factory must subclass org.wanghy.cache.provider.AbstractSingletonCacheManagerFactoryBean or, org.wanghy.cache.provider.AbstractConfigurationResourceCacheManagerFactoryBean if the factory uses a configuration file to create the cache manager. (with the exception of EHCache, which is provided by the Spring Framework)

  2. cacheProfiles (required).

    A cache profile tells the cache provider how to cache objects and how to flush the cache.

    Cache profiles can be defined as a:

    • java.util.Map

      This is the conventional way of setting up a map as a property of a bean definition. Since each entry of the map must be defined as a bean, we could end up with an excessively long and verbose configuration file.
    or as a:
    • java.util.Properties

      This is an alternative, simplified way to set up the cache profiles. Each cache profile is defined as a string of the form "[propertyName1=propertyValue1][propertyName2=propertyValue2]" where each of the properties of the cache profile is specified between brackets. The fully qualified class name is not necessary because the facade chooses the class of the cache profile that is suitable for the chosen cache provider.

  3. failQuietlyEnabled (optional).

    Indicates if an exception should thrown or not when an error occurrs when accessing the cache.

    Default value is false.

The following sections contain more details about setting up each supported cache provider.