1.11.1. Basic concepts

All applications on the top of eXo JCR that need a cache, can rely on an org.exoplatform.services.cache.ExoCache instance that is managed by the org.exoplatform.services.cache.CacheService. The main implementation of this service is org.exoplatform.services.cache.impl.CacheServiceImpl which depends on the org.exoplatform.services.cache.ExoCacheConfig in order to create new ExoCache instances. See the below example of org.exoplatform.services.cache.CacheService definition:


<component>
    <key>org.exoplatform.services.cache.CacheService</key>
    <jmx-name>cache:type=CacheService</jmx-name>
    <type>org.exoplatform.services.cache.impl.CacheServiceImpl</type>
    <init-params>
      <object-param>
        <name>cache.config.default</name>
        <description>The default cache configuration</description>
        <object type="org.exoplatform.services.cache.ExoCacheConfig">
          <field name="name"><string>default</string></field>
          <field name="maxSize"><int>300</int></field>
          <field name="liveTime"><long>600</long></field>
          <field name="distributed"><boolean>false</boolean></field>
          <field name="implementation"><string>org.exoplatform.services.cache.concurrent.ConcurrentFIFOExoCache</string></field> 
        </object>
      </object-param>
    </init-params>
  </component>

Note

The ExoCacheConfig that has the name "default" will be the default configuration of all the ExoCache instances.

See the below example about how to define a new ExoCacheConfig via an external-component-plugin:


<external-component-plugins>
    <target-component>org.exoplatform.services.cache.CacheService</target-component>
    <component-plugin>
        <name>addExoCacheConfig</name>
        <set-method>addExoCacheConfig</set-method>
        <type>org.exoplatform.services.cache.ExoCacheConfigPlugin</type>
        <description>Configures the cache for SEO service</description>
        <init-params>
            <object-param>
                <name>cache.config.wcm.seo</name>
                <description>The cache configuration for SEO</description>
                <object type="org.exoplatform.services.cache.ExoCacheConfig">
                    <field name="name">
                        <string>wcm.seo</string>
                    </field>
                    <field name="maxSize">
                        <int>${wcm.cache.seoservice.capacity:300}</int>
                    </field>
                    <field name="liveTime">
                        <long>${wcm.cache.seoservice.timetolive:600}</long>
                    </field>
                    <field name="distributed">
                        <boolean>false</boolean>
                    </field>
                    <field name="implementation">
                        <string>org.exoplatform.services.cache.concurrent.ConcurrentFIFOExoCache</string>
                    </field>
                </object>
            </object-param>
        </init-params>
    </component-plugin>
</external-component-plugins>

nameName of the cache. This field is mandatory since it will be used to retrieve the ExoCacheConfig corresponding to a given cache name.
labelLabel of the cache. This field is optional. It is mainly used to indicate the purpose of the cache.
maxSizeThe maximum numbers of elements in cache. This field is mandatory.
liveTimeThe amount of time (in seconds) that an element is not written or read before it is evicted. This field is mandatory.
implementationThe full qualified name of the cache implementation to use. This field is optional. This field is only used for simple cache implementation. The default and main implementation is org.exoplatform.services.cache.concurrent.ConcurrentFIFOExoCache that only works with local caches with FIFO as eviction policy. For more complex implementation, see the next sections.
distributedIndicates if the cache is distributed. This field is optional. This field is deprecated.
replicatedIndicates if the cache is replicated. This field is optional.
logEnabledIndicates if the log is enabled. This field is optional. This field is used for backward compatibility.
avoidValueReplicationIndicates whether the values of the cache should be replicated or not in case of a replicated cache. This field is optional. By default it is disabled. Find more details about this field in the next section.

Copyright ©. All rights reserved. eXo Platform SAS
blog comments powered byDisqus