1 55 package org.hibernate.cache; 56 57 import net.sf.ehcache.CacheManager; 58 59 import java.util.Properties ; 60 61 import org.apache.commons.logging.Log; 62 import org.apache.commons.logging.LogFactory; 63 64 74 public class EhCacheProvider implements CacheProvider { 75 76 private static final Log log = LogFactory.getLog(EhCacheProvider.class); 77 78 private static int referenceCount = 0; 83 84 private CacheManager manager; 85 86 99 public Cache buildCache(String name, Properties properties) throws CacheException { 100 try { 101 net.sf.ehcache.Cache cache = manager.getCache(name); 102 if (cache == null) { 103 log.warn("Could not find configuration [" + name + "]; using defaults."); 104 manager.addCache(name); 105 cache = manager.getCache(name); 106 log.debug("started EHCache region: " + name); 107 } 108 return new EhCache(cache); 109 } 110 catch (net.sf.ehcache.CacheException e) { 111 throw new CacheException(e); 112 } 113 } 114 115 118 public long nextTimestamp() { 119 return Timestamper.next(); 120 } 121 122 128 public void start(Properties properties) throws CacheException { 129 try { 130 manager = CacheManager.create(); 131 referenceCount++; 132 } 133 catch (net.sf.ehcache.CacheException e) { 134 throw new CacheException(e); 135 } 136 } 137 138 142 public void stop() { 143 if ( manager != null ) { 144 if ( --referenceCount == 0 ) { 145 manager.shutdown(); 146 } 147 manager = null; 148 } 149 } 150 151 public boolean isMinimalPutsEnabledByDefault() { 152 return false; 153 } 154 155 } 156 | Popular Tags |