Cache Extension

Cache Extension

1 Motivations

In the previous versions of eXo kernel, it was quite complex to implement your own ExoCache because it was not open enough. Since kernel 2.0.8, it is possible to easily integrate your favorite cache provider in eXo Products.

In fact in previous versions, you could only use few properties provided by ExoCachConfig to create your cache, as you can see below:

package org.exoplatform.services.cache;
...
public class ExoCacheConfig {

  /**
   * The name of the cache
   */
  private String  name;

  /**
   * The label of the cache
   */
  private String  label;

  /**
   * The maximum number of elements in your cache
   */
  private int     maxSize;

  /**
   * The amount of time (in milliseconds) an element is not written or
   * read before it is evicted. 
   */
  private long    liveTime;

  /**
   * Indicates if the cache is distributed
   */
  private boolean distributed;

  /**
   * Indicates if the cache is replicated
   */
  private boolean replicated;

  /**
   * The full qualified name of the cache implementation to use
   */
  private String  implementation;
  
  /**
   * Indicates if the log is enabled
   */
  private boolean logEnabled;
...

Unfortunately, it was really limited especially if we would like to integrate complex caches such as JBoss Cache, Oracle Coherence, etc.. So, it was necessary to try to open it a little bit more.

2 Overview

Since kernel 2.0.8, you just need to implement your own ExoCacheFactory and register it in an eXo container (as described here?), described below:

package org.exoplatform.services.cache;
...
public interface ExoCacheFactory {
  
  /**
   * Creates a new instance of {@link org.exoplatform.services.cache.ExoCache}
   * @param config the cache to create
   * @return the new instance of {@link org.exoplatform.services.cache.ExoCache}
   * @exception ExoCacheInitException if an exception happens while initializing the cache
   */
  public ExoCache createCache(ExoCacheConfig config) throws ExoCacheInitException;  
}

As you can see, there is only one method to implement which cans be seen as a converter of an ExoCacheConfig to get an instance of ExoCache. Once, you created your own implementation you can simply register your factory by adding a file conf/portal/configuration.xml with a content of the following type

<?xml version="1.0" encoding="ISO-8859-1"?>
<configuration>
  <component>
    <key>org.exoplatform.services.cache.ExoCacheFactory</key>
    <type>org.exoplatform.tutorial.MyExoCacheFactoryImpl</type>
    ...
  </component>   
</configuration>

For more details about how to configure a component in an eXo product, click here?

3 Available implementations

Tags:
Created by Nicolas Filotto on 07/24/2009
Last modified by Nicolas Filotto on 07/24/2009

Products

generated on Thu Sep 02 15:43:18 UTC 2010

eXo Optional Modules

eXo Core Foundations


Copyright (c) 2000-2010. All Rights Reserved - eXo platform SAS
2.4.30451