1 package org.roller.presentation.pagecache; 2 3 import java.io.IOException ; 4 import java.util.ArrayList ; 5 import java.util.Iterator ; 6 7 import javax.servlet.Filter ; 8 import javax.servlet.FilterChain ; 9 import javax.servlet.FilterConfig ; 10 import javax.servlet.ServletException ; 11 import javax.servlet.ServletRequest ; 12 import javax.servlet.ServletResponse ; 13 import javax.servlet.http.HttpServletRequest ; 14 15 import org.apache.commons.logging.Log; 16 import org.apache.commons.logging.LogFactory; 17 import org.roller.pojos.UserData; 18 import org.roller.presentation.filters.IfModifiedFilter; 19 import org.roller.presentation.pagecache.rollercache.LRUCacheHandler2; 20 21 22 38 public class PageCacheFilter implements Filter 39 { 40 private static Log mLogger = 41 LogFactory.getFactory().getInstance(PageCacheFilter.class); 42 43 private FilterHandler mHandler = null; 44 45 private static ArrayList mHandlers = new ArrayList (); 46 47 52 public void init(FilterConfig filterConfig) 53 { 54 if (mLogger.isDebugEnabled()) 55 { 56 mLogger.debug( 57 "Initializing as filterName: "+filterConfig.getFilterName()); 58 } 59 mHandler = new LRUCacheHandler2(filterConfig); 60 mHandlers.add(mHandler); 61 } 62 63 67 public void destroy() 68 { 69 mHandler.destroy(); 70 } 71 72 80 public void doFilter(ServletRequest request, 81 ServletResponse response, FilterChain chain) 82 throws ServletException , IOException 83 { 84 mHandler.doFilter(request, response, chain); 85 } 86 87 89 public static void flushCache(HttpServletRequest req) 90 { 91 Iterator iter = mHandlers.iterator(); 92 while (iter.hasNext()) 93 { 94 FilterHandler handler = (FilterHandler)iter.next(); 95 handler.flushCache(req); 96 } 97 IfModifiedFilter.purgeDateCache(null); 98 } 99 100 102 public static void removeFromCache(HttpServletRequest req, UserData user) 103 { 104 Iterator iter = mHandlers.iterator(); 105 while (iter.hasNext()) 106 { 107 FilterHandler handler = (FilterHandler)iter.next(); 108 handler.removeFromCache(req, user); 109 } 110 IfModifiedFilter.purgeDateCache(user); 111 } 112 } 113 | Popular Tags |