| 1 7 package com.dotmarketing.cache; 8 9 import java.io.FileInputStream ; 10 import java.io.FileNotFoundException ; 11 import java.io.IOException ; 12 import java.util.Properties ; 13 14 import com.dotmarketing.portlets.htmlpages.model.HTMLPage; 15 import com.dotmarketing.util.Config; 16 import com.dotmarketing.util.Logger; 17 import com.dotmarketing.util.UtilMethods; 18 19 25 public class PageNotFoundCache { 26 27 private static DotCache cache; 29 30 private static String providerEntry = "CACHE_PROVIDER"; 32 33 private static String propertiesEntry = "CACHE_PROPERTIES_FILE"; 35 36 private static String regionName = "PageNotFoundCache"; 38 39 static { 40 init(); 41 } 42 43 public static void clearCache() { 45 cache.clear(); 46 } 47 48 public static void destroy() { 49 cache.destroy(); 50 } 51 52 public static Object getPageFromCache(String URI) { 53 return cache.get(URI); 54 } 55 56 public static void addPageToCache(String URI) { 57 } 59 60 public static void removePageFromCache(String URI) { 62 63 cache.remove(URI); 64 } 65 66 public static void removePageFromCache(HTMLPage page) { 67 try { 68 long _x = page.getIdentifier(); 69 if (_x == 0) { 70 String pagePath = "/live/" + _x + "." + Config.getStringProperty("VELOCITY_HTMLPAGE_EXTENSION"); 71 removePageFromCache(pagePath); 72 } 73 } catch (Exception ex) { 74 Logger.error(PageNotFoundCache.class, ex.toString()); 75 } 76 } 77 78 protected static void unlock(Object key) { 79 cache.unlock(key); 80 } 81 82 protected static int getTimeout() { 83 return cache.getTimeout(); 84 } 85 86 protected static void lock(Object key) { 87 cache.lock(key); 88 } 89 90 protected static long nextTimestamp() { 91 return cache.nextTimestamp(); 92 } 93 94 96 private static void init() { 97 try { 98 Properties PageNotFountProperties = new Properties (); 99 String cacheProviderClassName = com.dotmarketing.util.Config.getStringProperty(providerEntry); 100 try { 101 String propertyFilePath = com.dotmarketing.util.Config.getStringProperty(propertiesEntry); 102 if (UtilMethods.isSet(propertyFilePath)) { 103 FileInputStream fileInputStream = new FileInputStream (propertyFilePath); 104 PageNotFountProperties.load(fileInputStream); 105 } 106 } catch (FileNotFoundException ex) { 107 108 String propertyFileNotFound = "The property file has been no found \n"; 109 Logger.debug(PageNotFoundCache.class, propertyFileNotFound + ex.getMessage()); 110 } catch (IOException ex) { 111 Logger.debug(PageNotFoundCache.class, ex.getMessage()); 112 } finally { 113 cache = new DotCache(cacheProviderClassName, regionName, PageNotFountProperties); 114 } 115 } catch (Exception ex) { 116 Logger.error(PageNotFoundCache.class, ex.toString()); 117 } 118 } 119 } 120 | Popular Tags |