1 7 package com.dotmarketing.cache; 8 9 import java.util.Properties ; 10 11 import com.dotmarketing.util.Logger; 12 import net.sf.hibernate.cache.Cache; 13 import net.sf.hibernate.cache.CacheException; 14 import net.sf.hibernate.cache.CacheProvider; 15 16 22 public class DotCache implements Cache { 23 24 private CacheProvider provider; 26 27 private Cache cache; 29 30 private String defaultProvider = "net.sf.ehcache.hibernate.Provider"; 32 33 public DotCache(String cacheProviderClassName,String regionName, Properties properties) { 35 cacheProviderClassName = (cacheProviderClassName != null ? cacheProviderClassName : defaultProvider); 37 if (properties == null) 39 { 40 properties = new Properties (); 41 } 42 43 try 45 { 46 Class classDefinition = Class.forName(cacheProviderClassName); 47 provider = (CacheProvider) classDefinition.newInstance(); 48 cache = provider.buildCache(regionName, properties); 49 } 50 catch (InstantiationException e) 51 { 52 Logger.debug(DotCache.class,e.toString()); 53 } 54 catch (IllegalAccessException e) 55 { 56 Logger.debug(DotCache.class,e.toString()); 57 } 58 catch (ClassNotFoundException e) 59 { 60 Logger.debug(DotCache.class,e.toString()); 61 try 62 { 63 Class classDefinition = Class.forName(defaultProvider); 64 provider = (CacheProvider) classDefinition.newInstance(); 65 cache = provider.buildCache(regionName, properties); 66 } 67 catch(Exception ex) 68 { 69 Logger.error(DotCache.class,ex.toString()); 70 } 71 } 72 catch (CacheException cacheEx) 73 { 74 Logger.debug(DotCache.class,cacheEx.toString()); 75 } 76 } 77 78 public void clear() 80 { 81 try 82 { 83 cache.clear(); 84 } 85 catch (Exception cacheEx) 86 { 87 Logger.debug(DotCache.class,cacheEx.getMessage()); 88 } 89 } 90 91 public void destroy() 92 { 93 try 94 { 95 cache.destroy(); 96 } 97 catch (Exception cacheEx) 98 { 99 Logger.debug(DotCache.class,cacheEx.getMessage()); 100 } 101 } 102 103 public Object get(Object key) 104 { 105 Object returnValue = null; 106 try 107 { 108 returnValue = cache.get(key); 109 } 110 catch (Exception cacheEx) 111 { 112 Logger.debug(DotCache.class,cacheEx.getMessage()); 113 } 114 return returnValue; 115 } 116 117 public int getTimeout() 118 { 119 return cache.getTimeout(); 120 } 121 122 public void lock(Object key) 123 { 124 try 125 { 126 cache.lock(key); 127 } 128 catch (Exception cacheEx) 129 { 130 Logger.debug(DotCache.class,cacheEx.getMessage()); 131 } 132 } 133 134 public long nextTimestamp() 135 { 136 return cache.nextTimestamp(); 137 } 138 139 public void put(Object key, Object value) 140 { 141 try 142 { 143 cache.put(key,value); 144 } 145 catch (Exception cacheEx) 146 { 147 Logger.debug(DotCache.class,cacheEx.getMessage()); 148 } 149 } 150 151 public void remove(Object key) 152 { 153 try 154 { 155 cache.remove(key); 156 } 157 catch (Exception cacheEx) 158 { 159 Logger.debug(DotCache.class,cacheEx.getMessage()); 160 } 161 } 162 163 public void unlock(Object key) 164 { 165 try 166 { 167 cache.unlock(key); 168 } 169 catch (Exception cacheEx) 170 { 171 Logger.debug(DotCache.class,cacheEx.getMessage()); 172 } 173 } 174 } 176 | Popular Tags |