Getting Cache from Cache Manager

To get an instance of a cache call getCache(String cacheName) method of the cache manager. The example below shows how to get a cache from the cache manager:

package com.cacheonix.examples.cache;

import junit.framework.TestCase;
import cacheonix.cache.Cache;
import cacheonix.cache.CacheManager;

/**
 * Tester for Cache.
 */
public final class CacheManagerTest extends TestCase {

   private CacheManager cacheManager;


   /**
    * Tests getting an instance of Cache.
    */
   public void testGetCache() {
      final Cache cache = cacheManager.getCache("test_cache");
      assertNotNull("Cache returned by cacheManager should be not null", cache);
      assertEquals("test_cache", cache.getName());
   }


   /**
    * Sets up the fixture. This method is called before a test is executed.
    */
   protected void setUp() throws Exception {
      super.setUp();
      cacheManager = CacheManager.getInstance();
   }


   /**
    * Tears down the fixture. This method is called after a test is executed.
    */
   protected void tearDown() throws Exception {
      // Cache manager has to be shutdown upon application exit
      cacheManager.shutdown();
      super.tearDown();
   }
}

Labels

 
(None)