Configuring Local Cacheonix

Cacheonix provides a free local cache. The local cache does not require a license.

Local Cacheonix is configured using element local. Below is a complete example of cacheonix-config.xml that configures a set of two local caches and a template:

<?xml version ="1.0"?>
<cacheonix xmlns="http://www.cacheonix.com/schema/configuration"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://www.cacheonix.com/schema/configuration http://www.cacheonix.com/schema/cacheonix-config-2.0.xsd">

   <local>

      <localCache name="configuration.cache">
         <store>
            <lru maxElements="1000" maxBytes="10mb"/>
            <overflowToDisk maxOverflowBytes="1mb"/>
            <expiration timeToLive="1s"/>
         </store>
      </localCache>

      <localCache name="status.cache">
         <store>
            <lru maxElements="1000" maxBytes="10mb"/>
            <overflowToDisk maxOverflowBytes="1mb"/>
            <expiration timeToLive="1s"/>
         </store>
      </localCache>

      <localCache name="default" template="true">
         <store>
            <lru maxElements="10" maxBytes="10mb"/>
            <overflowToDisk maxOverflowBytes="1mb"/>
            <expiration timeToLive="1s"/>
         </store>
      </localCache>

   </local>
</cacheonix>

The following sections discusses configuring various aspects of Cacheonix.

Configuring Local Cache

Use element locaCache to configure a local cache. Below is a fragment of cacheonix-config.xml that configures a local cache backed by an LRU store:

<localCache name="configuration.cache">
     <store>
        <lru maxElements="1000" maxBytes="10mb"/>
        <overflowToDisk maxOverflowBytes="1mb"/>
        <expiration timeToLive="1s"/>
     </store>
</localCache>

Configuring Cache Expiration

Cacheonix provides two ways to control cache eviction bases on time, particularly, attributes timeToLive and idleTime. Optional attribute timeToLive defines for how long a key may stay in the cache before the cache removes it. Optional attribute idleTime defines for how long a key may stay in the cache without being accessed for read or write. Example:

<localCache name="configuration.cache">
     <store>
        <lru maxElements="1000" maxBytes="10mb"/>
        <overflowToDisk maxOverflowBytes="1mb"/>
        <expiration timeToLive="60s" idleTime="30s"/>
     </store>
</localCache>

Configuring Cache Data Source

A cache can be configured with an optional supplier of data for the case when a key is not in the cache (a cache miss). Implement interface cacheonix.cache.datasource.CacheDataSource to be able to populate the cache lazily from a database or from any other source of data. Classes implementing cacheonix.cache.datasource.CacheDataSource must provide a public un-protected no-argument constructor. Configure the cache data source by adding dataSource element to the cache configuration:

<localCache name="property.cache">
     <store>
        <lru maxElements="10" maxBytes="10mb"/>
        <expiration timeToLive="1s"/>

        <dataSource className="cacheonix.cache.datasource.PropertyCacheDataSource"/>

     </store>
</localCache>

Check an example of an implementation of cacheonix.cache.datasource.CacheDataSource.

Labels