Child pages
  • Using Caching in Sakai
Skip to end of metadata
Go to start of metadata

Out of date

This information is no longer correct for newer versions of Sakai (2.7+)


This documents the proper way to do caching in Sakai. This will be updated as improvements are made to the Sakai caching system.

Caching in 2.5+ and trunk

Using the Sakai CacheManager is the recommended way to handle caching in Sakai 2.5+. It will be required for the kernel. This is expressed as a Spring Bean Factory with the id org.sakaiproject.memory.api.MemoryService.cacheManager

  1. Create a cache in your service (in the components.xml) like so:

    <bean id="org.sakaiproject.user.api.UserDirectoryService.cache"
      <property name="cacheManager">
        <ref bean="org.sakaiproject.memory.api.MemoryService.cacheManager"/>
      <property name="cacheName">
  2. Spring inject the cache into your service like so:

    <bean id="org.sakaiproject.user.api.UserDirectoryService" ...
      <property name="cache">
        <ref bean="org.sakaiproject.user.api.UserDirectoryService.cache" />
  3. Use the cache within your code:

    cache.put(new Element(key,value));
  • 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

Caching in 2.4 or earlier is best done using the MemoryService

  • No labels

1 Comment

  1. A note that the Cache in your Java class needs to be of type net.sf.ehcache.Cache not org.sakaiproject.memory.api.Cache (in case you were wondering).