1 5 package org.exoplatform.services.cache.impl; 6 7 import java.util.Collection ; 8 import java.util.HashMap ; 9 10 import org.exoplatform.services.cache.CacheService; 11 import org.exoplatform.services.cache.ExoCache; 12 import org.exoplatform.services.cache.SimpleExoCache; 13 import org.picocontainer.Startable ; 14 21 public class SimpleCacheService implements CacheService, Startable { 22 private HashMap cacheMap_ ; 23 24 public SimpleCacheService() { 25 cacheMap_ = new HashMap () ; 26 } 27 28 public ExoCache getCacheInstance(String region) throws Exception { 29 if( region == null || region.length() == 0) { 30 throw new Exception ("region cannot be empty"); 31 } 32 ExoCache cache = (ExoCache) cacheMap_.get(region) ; 33 if (cache == null) { 34 synchronized (cacheMap_) { 35 cache = new SimpleExoCache(region, 100) ; 36 cacheMap_.put(region, cache) ; 37 } 38 } 39 return cache ; 40 } 41 42 public Collection getAllCacheInstances() throws Exception { 43 return cacheMap_.values() ; 44 } 45 46 public void start() { } 47 public void stop() {} 48 } 49 50 | Popular Tags |