This is a Java servlet filter (as per Servlet API 2.3). CacheFilter lets you use cached output from your jsp pages. You will provide an initial parameter to this filter as an XML file where you will describe your cache policy: directory for saving cached data, names for pages you need to be cached, timeouts for keeping data in cache. So instead of calculation filter will output cached data directly. How to use it: a) download cacheflt.jar and save it in WEB-INF/lib b) describe this filter in web.xml. The name for initial parameter is
config. Parameter value is a path to XML file where you will describe your
cache policy.
<filter> <filter-name>cacheFilter</filter-name> <filter-class>com.cj.cacheflt.cacheFilter</filter-class> <init-param> <param-name>config</param-name> <param-value>path_to_your_file</param-value> </init-param> </filter> cacheServlet provides a console:
<servlet> <servlet-name>cacheServlet</servlet-name> <servlet-class>com.cj.cacheflt.cacheServlet</servlet-class> <init-param> <param-name>config</param-name> <param-value>path_to_your_file</param-value> </init-param> </servlet> c) describe a mapping for this filter in web.xml
<filter-mapping> <filter-name>cacheFilter</filter-name> <url-pattern>*.jsp</url-pattern> </filter-mapping> in this case filter will be on for the each .jsp file Also you may exclude some of your files from the processing. Parameter
exclude contains a regular expresion to match excluded urls. E.g.:
<filter> <filter-name>cacheServlet</filter-name> <filter-class>com.cj.cacheflt.cacheServlet</filter-class> <init-param> <param-name>config</param-name> <param-value>path_to_your_file</param-value> </init-param> <init-param> <param-name>exclude</param-name> <param-value>/login.jsp</param-value> </init-param> </filter> And now when you invoke any .jsp page: http://your_host/your_page.jsp cacheFilter will check out cache settings for the given page and proceed request. You can see live stats for cache through cacheServlet: http://host/servlet/cacheServlet Configuration file is XML file. You must define the following elements:
Config => (cache, +page) cache - defines a directory for cache. It is just any existing directory
on your server. Note: all files from this directory will be deleted!. E.g.:
page - defines a cached page. Attributes are:
<page uri="p1.jsp" time="-1" type="text/html" varyByHeader="user-agent"/> <page uri="dir/subdir/page.jsp" time="600" type="text/html" /> Here for example the first directive allows you to provide cached versions of p1.jsp for the different browsers. Notes: 1. Servlet uses JAXP for parsing XML file. 2. Config file can be saved anywhere on your server. You may use the full path for setting data file location. For downloading:
See also JSOS - the largest collection of servlets and filters.
|
Also in JSOS:
|