This explains basic usage of the Sakai MemoryService. This service manages and is used to create and retrieve information about existing caches.

Accessing the MemoryService

  1. Using Spring to get the service for your class (e.g. YourAppClass) (recommended)
    1. Add the MemoryService bean to the bean for YourAppClass

      <bean id="org.sakaiproject.yourapp.logic.YourAppClass"
      	<property name="memoryService"
      		ref="org.sakaiproject.memory.api.MemoryService" />
    2. Add a variable and setter to YourAppClass to use the service in like so:

      private MemoryService memoryService;
      public void setMemoryService(MemoryService memoryService) {
      	this.memoryService = memoryService;
  2. Using the Component Manager to get the service
    1. Use the CM cover to get the service

      import org.sakaiproject.component.cover.ComponentManager;
        private MemoryService memoryService;
          memoryService = (MemoryService) ComponentManager.get(MemoryService.class);

Getting a Cache by name

  1. Use the service variable to access the service and request a Cache. This will create one if needed or retrieve an existing one if it was created earlier.

    Cache myCache = memoryService.getCache("");