Warning | ||
---|---|---|
| ||
This information is no longer correct for newer versions of Sakai (2.7+) |
Information
This documents the proper way to do caching in Sakai. This will be updated as improvements are made to the Sakai caching system.
...
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
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>
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>
Use the cache within your code:
Code Block java java cache.get(key).getObjectValue(); cache.put(new Element(key,value)); cache.remove(key);
...