이 Cache Filter를 사용하면 JSP, Servlet은 물론 정적인 컨텐트도 캐싱할 수 있다. 예를 들어 웹로직
을 웹서버로 활용할 경우 HTML이나 GIF, JPEG 등의 정적인 컨텐트를 메모리에 올려 놓고 사용하면 큰 성능
향상 효과를 얻을 수 있다. (web.xml)
Response Caching
The cache filter works similarly to the cache tag with the following exceptions:
- It caches on a page level (or included page) instead of a JSP fragment level.
- Instead of declaring the caching parameters inside the document you can declare the parameters in the configuration of the web application.
The cache filter has some default behavior that the cache tag does not for pages that were not included from another page. The cache filter automatically caches the response headers Content-Type and Last-Modified. When it receives a request that results in a cached page it compares the If-Modified-Since request header to the Last-Modified response header to determine whether it needs to actually serve the content or if it can send an 302 SC_NOT_MODIFED status with an empty content instead.
The following example shows how to register a cache filter to cache all the HTML pages in a web app:
<filter-name>HTML</filter-name>
<filter-class>weblogic.cache.filter.CacheFilter</filter-class>
<filter-name>HTML</filter-name>
<url-pattern>*.html</url-pattern>
The cache system uses soft references for storing the cache. So the garbage collector might or might not reclaim the cache depending on how recently the cache was created or accessed. It will clear the soft references in order to avoid throwing an OutOfMemoryError.
Initialization Parameters
If you wanted to make sure that if the web pages were updated at some point you got the new copies into the cache, you could add a timeout to the filter. Using the init-params you can set many of the same parameters that you can set for the cache tag:
The initialization parameters are
NameThis is the name of the cache. It defaults to the request URI for compatibility with *.extension URL patterns.TimeoutThis is the amount of time since the last cache update that the filter waits until trying to update the content in the cache again. The default unit is seconds but you can also specify it in units of ms (milliseconds), s (seconds), m (minutes), h (hours), or d (days).ScopeThe scope of the cache can be any one of request, session, application, or cluster. Request scope is sometimes useful for looping constructs in the page and not much else. The scope defaults to application. To use cluster scope you must set up the ClusterListener.KeyThis specifies that the cache is further specified not only by the name but also by values of various entries in scopes. These are specified just like the keys in the CacheTag although you do not have page scope available.VarsThese are the variables calculated by the page that you want to cache. Typically this is used with servlets that pull information out of the database based on input parameters.SizeThis limits the number of different unique key values cached. It defaults to infinity.
The following example shows where the init-parameter is located in the filter code.
<filter-name>HTML</filter-name>
<filter-class>weblogic.cache.filter.CacheFilter</filter-class>