1 13 package info.magnolia.cms.beans.runtime; 14 15 import info.magnolia.cms.core.Path; 16 17 import java.util.Hashtable ; 18 import java.util.Map ; 19 20 import javax.servlet.http.HttpServletRequest ; 21 22 import org.apache.commons.lang.StringUtils; 23 import org.apache.log4j.Logger; 24 25 26 30 public final class Cache { 31 32 35 private static Map cachedURIList = new Hashtable (); 36 37 40 private static Logger log = Logger.getLogger(Cache.class); 41 42 46 private static Map inProcessURIList = new Hashtable (); 47 48 51 private long time; 52 53 56 private int size; 57 58 61 private int compressedSize; 62 63 66 private Cache() { 67 } 69 70 74 public static boolean isCached(HttpServletRequest request) { 75 return Cache.cachedURIList.get(Path.getURI(request)) != null; 76 } 77 78 82 public static boolean isInCacheProcess(HttpServletRequest request) { 83 return Cache.inProcessURIList.get(Path.getURI(request)) != null; 84 } 85 86 89 public static void addToInProcessURIList(String uri) { 90 Cache.inProcessURIList.put(uri, StringUtils.EMPTY); 91 } 92 93 96 public static void removeFromInProcessURIList(String uri) { 97 Cache.inProcessURIList.remove(uri); 98 } 99 100 103 public static void clearInProcessURIList() { 104 Cache.inProcessURIList.clear(); 105 } 106 107 114 public static void addToCachedURIList(String uri, long lastModified, int size, int compressedSize) { 115 Cache cacheMap = new Cache(); 116 cacheMap.time = lastModified; 117 cacheMap.size = size; 118 cacheMap.compressedSize = compressedSize; 119 if (log.isDebugEnabled()) { 120 log.debug("Caching URI [" + uri + "]"); } 122 Cache.cachedURIList.put(uri, cacheMap); 123 } 124 125 128 public static void removeFromCachedURIList(String uri) { 129 Cache.cachedURIList.remove(uri); 130 } 131 132 135 public static void clearCachedURIList() { 136 Cache.cachedURIList.clear(); 137 } 138 139 143 public static long getCreationTime(HttpServletRequest request) { 144 Cache cacheMap = (Cache) cachedURIList.get(Path.getURI(request)); 145 if (cacheMap == null) { 146 return -1; 147 } 148 return cacheMap.time; 149 } 150 151 155 public static int getSize(HttpServletRequest request) { 156 Cache cacheMap = (Cache) cachedURIList.get(Path.getURI(request)); 157 return cacheMap.size; 158 } 159 160 164 public static int getCompressedSize(HttpServletRequest request) { 165 Cache cacheMap = (Cache) cachedURIList.get(Path.getURI(request)); 166 return cacheMap.compressedSize; 167 } 168 169 175 public static long getCreationTime(String uri) { 176 Cache cacheMap = (Cache) cachedURIList.get(uri); 177 if (cacheMap == null) { 178 return -1; 179 } 180 return cacheMap.time; 181 } 182 183 189 public static int getSize(String uri) { 190 Cache cacheMap = (Cache) cachedURIList.get(uri); 191 return cacheMap.size; 192 } 193 194 200 public static int getCompressedSize(String uri) { 201 Cache cacheMap = (Cache) cachedURIList.get(uri); 202 return cacheMap.compressedSize; 203 } 204 205 211 public static boolean isCached(String uri) { 212 return Cache.cachedURIList.get(uri) != null; 213 } 214 215 221 public static boolean isInCacheProcess(String uri) { 222 return Cache.inProcessURIList.get(uri) != null; 223 } 224 225 } 226 | Popular Tags |