Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  1. Create a cache in your service (in the components.xml) like so:
    Code Block
    xml
    xml
    <bean id="org.sakaiproject.user.api.UserDirectoryService.cache"
        class="org.springframework.cache.ehcache.EhCacheFactoryBean">
      <property name="cacheManager">
        <ref bean="org.sakaiproject.memory.api.MemoryService.cacheManager"/>
      </property>
      <property name="cacheName">
        <value>org.sakaiproject.user.api.UserDirectoryService</value>
      </property>
    </bean>
    
  2. Spring inject the cache into your service like so:
    Code Block
    xml
    xml
    <bean id="org.sakaiproject.user.api.UserDirectoryService" ...
    ...
      <property name="cache">
        <ref bean="org.sakaiproject.user.api.UserDirectoryService.cache" />
      </property>
    </bean>
    
  3. Use the cache within your code:
    Code Block
    java
    java
    cache.get(key).getObjectValue();
    cache.put(new Element(key,value));
    cache.remove(key);
    
  • NOTE This cache is not cluster wide and exists on one server only. You have to handle cluster wide expiring yourself.

Caching in 2.4 or earlier

...