KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > roller > presentation > pagecache > PageCacheFilter


1 package org.roller.presentation.pagecache;
2
3 import java.io.IOException JavaDoc;
4 import java.util.ArrayList JavaDoc;
5 import java.util.Iterator JavaDoc;
6
7 import javax.servlet.Filter JavaDoc;
8 import javax.servlet.FilterChain JavaDoc;
9 import javax.servlet.FilterConfig JavaDoc;
10 import javax.servlet.ServletException JavaDoc;
11 import javax.servlet.ServletRequest JavaDoc;
12 import javax.servlet.ServletResponse JavaDoc;
13 import javax.servlet.http.HttpServletRequest JavaDoc;
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 /////////////////////////////////////////////////////////////////////////////
23
/**
24  * Roller's in memory page cache. See Javadoc for LRUCacheHandler for more
25  * information on configuring this cache.
26  *
27  * @web.filter name="PageCacheFilter"
28  *
29  * @web.filter-init-param name="size" value="100"
30  * description="Number of pages to keep in cache"
31  *
32  * @web.filter-init-param name="timeout" value="1800"
33  * description="Page Cache timeout interval in seconds"
34  *
35  * @author Lance Lavandowska
36  * @author David M Johnson
37  */

38 public class PageCacheFilter implements Filter JavaDoc
39 {
40     private static Log mLogger =
41         LogFactory.getFactory().getInstance(PageCacheFilter.class);
42         
43     private FilterHandler mHandler = null;
44     
45     private static ArrayList JavaDoc mHandlers = new ArrayList JavaDoc();
46
47     //-----------------------------------------------------------------------
48
/**
49      * Initialize the filter.
50      * @param filerConfig The filter configuration
51      */

52     public void init(FilterConfig JavaDoc 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     //-----------------------------------------------------------------------
64
/**
65      * Filter clean-up
66      */

67     public void destroy()
68     {
69         mHandler.destroy();
70     }
71
72     //-----------------------------------------------------------------------
73
/**
74      * Process the doFilter
75      * @param request The servlet request
76      * @param response The servlet response
77      * @param chain The filet chain
78      * @throws ServletException IOException
79      */

80     public void doFilter(ServletRequest JavaDoc request,
81         ServletResponse JavaDoc response, FilterChain JavaDoc chain)
82         throws ServletException JavaDoc, IOException JavaDoc
83     {
84         mHandler.doFilter(request, response, chain);
85     }
86
87     //-----------------------------------------------------------------------
88
/** Flush cache for all handlers of this class */
89     public static void flushCache(HttpServletRequest JavaDoc req)
90     {
91         Iterator JavaDoc 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     //-----------------------------------------------------------------------
101
/** Remove from cache for all handlers of this class */
102     public static void removeFromCache(HttpServletRequest JavaDoc req, UserData user)
103     {
104         Iterator JavaDoc 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