OSCache 配置缓存过滤器 官方文档 中文翻译
原文连接 http://blog.csdn.net/citi007/article/details/6700348
配置缓存过滤器
翻译 Allchin
of your website, and even binary files. Caching of binary files is extremely useful when
they are generated dynamically, e.g. PDF files or images.
improvements can be done with the CacheFilter.
Beginning with release 2.4 you are be able to set/override the CacheFilter initialization
parameters at runtime.
Cacheable content
Note that the filter will only cache content that has a status of 200
To configure the filter, use the oscache.properties to configure the core settings of
OSCache and add something like the following to your web.xml file:
为了配置过滤器,使用 oscache.properties 去配置 OSCache 的核心设置并在 web.xml 中增加如下内容.
<filter>
<filter-name>CacheFilter</filter-name>
<filter-class>com.opensymphony.oscache.web.filter.CacheFilter</filter-class>
<init-param>
<param-name>time</param-name>
<param-value>600</param-value>
</init-param>
<init-param>
<param-name>scope</param-name>
<param-value>session</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>CacheFilter</filter-name>
<url-pattern>*.jsp</url-pattern>
</filter-mapping>
Obviously you will want to set the URL pattern to match only the content you want to
cache; this example will cache all JSP pages for 10 minutes in session scope. The default
duration is one hour and the default scope for the cache is application scope.
If the ICacheKeyProvider parameter isn't set, the CacheFilter will use the HTTP request
URI and the QueryString to create the cache key.
你可以通过使用下面的初始化参数来改变缓存过滤器的设置.
Parameter: time 时间
The time parameter sets the cache time (in seconds) for the content. The default cache
time is one hour.
stale until it is either explicitly flushed or the expires refresh policy causes the entry to
expire.
规定-1(不限时间)为缓存时间将会保证正文在显示的刷出或满足过期刷新时间引起过期前保持新鲜。
are application (default) and session.
A cron expression that determines when the page content will expire. This allows content
to be expired at particular dates and/or times, rather than once a cache entry reaches a
certain age. See Cron Expressions to read more about this attribute. Please consider that
the (default) time value is still evaluated, hence the time value should be set to indefinite
expiry.
一个 crom 表达式将会决定页面内容何时过期。这允许正文在特定的时间过期,就像一个缓存实体到达了确定的年龄一
样.参见 cron 表达式来了解该属性更加详细的内容。请考虑默认的时间值其实还是很有参考价值的,应此这个时间值因
Defines if the filter handles fragments of a page. Acceptable values are auto for auto
detect, no for false and yes for true. The default value is auto detect which checks the
javax.servlet.include.request_uri request attribute. Fragments of a page shouldn't be
gzipped or evaluate the last modified header.
定义了过滤器在一个页面上是否控制碎片。可以接受的值有 auto 自动选择,no 不使用,yes 使用.默认值是自动,它
将会检查 javax.servlet.include.request_uri 请求参数。页面碎片应该被 gzip 压缩或者用最后修改的头文件评
Defines which objects shouldn't be cached. Acceptable values are off (default) for caching
all objects and sessionIdInURL for don't cache page if the session id is contained in the
URL.
定义哪些对象不会被缓存。可以有的值是 off(默认),就是缓存所有对象,sessionIdInURL 表示如果 session id 被
Defines if the last modified header will be sent in the response. Acceptable values are off
for don't sending the header, even it is set in the filter chain, on for sending it if it is set in
the filter chain and initial (default) the last modified information will be set based on
current time.
定义了最后修改过的头是否将会被响应发送。可接受的值是 off,不去发送头,即使它是在过滤器链表中设置的,on,
Specifies the maximum amount of time in seconds that the cache content will be
considered new in the browser's cache. The browser will retrieve the content from it's
own cache for the amount of time without requesting the web server again. The default
max-age time is 60 seconds. Combined with the last modified header the transaction
overhead and server load is reduced excellently which speed ups the server response
time. Further parameters are no init for don't initializing the max-age cache control and
time to set max-age based on the time parameter and creation time of the content
(expiration timestamp minus current timestamp) by each request.
规定了最大的以妙为单位规定的加载时间,在此时间内的缓存正文将被认为是新的浏览器缓存。浏览器经会从它自己的
缓存中回收那些加载后超时的没有再请求服务器的正文。默认的最大年龄是 60 秒.最大年龄与最后修改头联合使用
会卓越的减少事物过载与服务器负载,获得超赞的响应时间 .更加深入的参数是 no init,不初始化最大年龄缓存控
Defines if the expires header will be sent in the response. Acceptable values are off for
don't sending the header, even it is set in the filter chain, on (default) for sending it if it is
set in the filter chain and time the expires information will be intialized based on the time
parameter and creation time of the content.
定义过期的头是否在响应中被发送.可选的值有 off,不发送,即使是在过滤器链表中设置它了,on(默认)发送,当在
过滤器链表中设置的时候启用,time,过期信息将会根据 time 参数与内容创建时间被初始化.
Value 'time'
The parameter time would force the CacheFilter to send the expires
header, because the value is set always. The developer must consider
that some browsers evaluate the value and will use the cached content
in the browsers cache, until the content is expired. Consequently a
flush of the cache in the web application won't update a page in the
browser cache. Hence different users may see see a different status of
page.
选项时间将会强制缓存过滤器发送过期头,应为这个是经常被使用的。开发者必须考虑一些浏览
器使用并评估这个值并用这些缓存的内容作为浏览器缓存,直到内容过期.从而 web 应用的缓
implement a class which provides cache keys based on the request, the servlect cache
administrator and the cache.
一个实现了 ICacheKeyProvider 接口的特定类。开发者实现这样一个类提供基于请求的缓存主键,管理对
servlet 的缓存和缓存.
Parameter: ICacheGroupsProvider (NEW! Since 2.2)缓存组提供器
Specify a class which implements the interface ICacheGroupsProvider. A developer can
implement a class which provides cache groups based on the request, the servlect cache
administrator and the cache.
一个实现接口 ICacheGroupsProvider 的类.一个开发者可以实现这个类就能够提供给予请求的缓存组,管理
Specify a class which implements the interface EntryRefreshPolicy. A developer can
implement a class which provides a different custom cache invalidation policy for a
specific cache entry. If not specified, the default policy is timed entry expiry as specified
with the time parameter described above.
定义一个实现接口 EntryRefreshPolicy 的类。开发者能够实现这个类为一个特别的缓存入口自定义缓存失效规则.
Specify HTTP method names in a comma separated list for which cacheing should be
disabled. The default value is <code>null</code> for cacheing all requests without
regarding the method name. See HttpServletRequest#getMethod, e.g.:
在以,分割的列表中定义 HTTP 方法名称就可以对他们禁用缓存。默认值是 null ,这会忽视方法名称而缓存所有请求.
参见 HttpServletRequest 的 getMethod 方法
<init-param>
<param-name>disableCacheOnMethods</param-name>
<param-value>POST,PUT,DELETE</param-value>
By specifying a OSCache properties file for a CacheFilter, the developer can run multiple
caches each with different configurations tailored to the requirements of the application.
In each properties file the developer has to define a unique cache.key otherwise the
default properties file is used. If the parameter is not specified, the default properties file
will be used. The file has to be put into the classpath, e.g. WEB-INF/classes.
为一个缓存过滤器定义一个 OSCache 属性文件,开发者可以为应用不同需求进行细化合理的配置并使用多个缓存。
为每个属性文件开发者必须定义一个唯一缓存主键 cache.key,否则会使用默认属性文件定义的缓存主键.这些文件需
要被放在类路径下,比如 WEB-INF/classes 下面.
原文连接 http://blog.csdn.net/citi007/article/details/6700348
配置缓存过滤器
翻译 Allchin
email:citi007@126.com
of your website, and even binary files. Caching of binary files is extremely useful when
they are generated dynamically, e.g. PDF files or images.
缓存过滤器在缓存动态创建的 PDF 或图像时还是相当有用的.
improvements can be done with the CacheFilter.
Beginning with release 2.4 you are be able to set/override the CacheFilter initialization
parameters at runtime.
从 2.4 版本开始你可以在运行时设置/覆盖缓存过滤器初始化参数.
Cacheable content
Note that the filter will only cache content that has a status of 200
(HttpServletResponse.SC_OK).
To configure the filter, use the oscache.properties to configure the core settings of
OSCache and add something like the following to your web.xml file:
为了配置过滤器,使用 oscache.properties 去配置 OSCache 的核心设置并在 web.xml 中增加如下内容.
<filter>
<filter-name>CacheFilter</filter-name>
<filter-class>com.opensymphony.oscache.web.filter.CacheFilter</filter-class>
<init-param>
<param-name>time</param-name>
<param-value>600</param-value>
</init-param>
<init-param>
<param-name>scope</param-name>
<param-value>session</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>CacheFilter</filter-name>
<url-pattern>*.jsp</url-pattern>
</filter-mapping>
Obviously you will want to set the URL pattern to match only the content you want to
cache; this example will cache all JSP pages for 10 minutes in session scope. The default
duration is one hour and the default scope for the cache is application scope.
If the ICacheKeyProvider parameter isn't set, the CacheFilter will use the HTTP request
URI and the QueryString to create the cache key.
如果 ICacheKeyProvider 参数没有被设置,缓存过滤器将会使用 HTTP 请求 URI 与查询字符串去创建缓存主键.
你可以通过使用下面的初始化参数来改变缓存过滤器的设置.
Parameter: time 时间
The time parameter sets the cache time (in seconds) for the content. The default cache
time is one hour.
时间参数设定了缓存内容的时间(秒为单位).默认缓存时间是一个小时
stale until it is either explicitly flushed or the expires refresh policy causes the entry to
expire.
规定-1(不限时间)为缓存时间将会保证正文在显示的刷出或满足过期刷新时间引起过期前保持新鲜。
Parameter: scope 范围
are application (default) and session.
范围参数让你设置缓存正文存在的范围。有效值是 applicaion(默认)与 session
A cron expression that determines when the page content will expire. This allows content
to be expired at particular dates and/or times, rather than once a cache entry reaches a
certain age. See Cron Expressions to read more about this attribute. Please consider that
the (default) time value is still evaluated, hence the time value should be set to indefinite
expiry.
一个 crom 表达式将会决定页面内容何时过期。这允许正文在特定的时间过期,就像一个缓存实体到达了确定的年龄一
样.参见 cron 表达式来了解该属性更加详细的内容。请考虑默认的时间值其实还是很有参考价值的,应此这个时间值因
该被设定为无限循环的。
Defines if the filter handles fragments of a page. Acceptable values are auto for auto
detect, no for false and yes for true. The default value is auto detect which checks the
javax.servlet.include.request_uri request attribute. Fragments of a page shouldn't be
gzipped or evaluate the last modified header.
定义了过滤器在一个页面上是否控制碎片。可以接受的值有 auto 自动选择,no 不使用,yes 使用.默认值是自动,它
将会检查 javax.servlet.include.request_uri 请求参数。页面碎片应该被 gzip 压缩或者用最后修改的头文件评
估。
Defines which objects shouldn't be cached. Acceptable values are off (default) for caching
all objects and sessionIdInURL for don't cache page if the session id is contained in the
URL.
定义哪些对象不会被缓存。可以有的值是 off(默认),就是缓存所有对象,sessionIdInURL 表示如果 session id 被
包含在 URL 中的时候不缓存页面.
Defines if the last modified header will be sent in the response. Acceptable values are off
for don't sending the header, even it is set in the filter chain, on for sending it if it is set in
the filter chain and initial (default) the last modified information will be set based on
current time.
定义了最后修改过的头是否将会被响应发送。可接受的值是 off,不去发送头,即使它是在过滤器链表中设置的,on,
发送它如果链表中设置了,initial(默认),最后修改的信息(根据但前的时间计算)将被发送。
Specifies the maximum amount of time in seconds that the cache content will be
considered new in the browser's cache. The browser will retrieve the content from it's
own cache for the amount of time without requesting the web server again. The default
max-age time is 60 seconds. Combined with the last modified header the transaction
overhead and server load is reduced excellently which speed ups the server response
time. Further parameters are no init for don't initializing the max-age cache control and
time to set max-age based on the time parameter and creation time of the content
(expiration timestamp minus current timestamp) by each request.
规定了最大的以妙为单位规定的加载时间,在此时间内的缓存正文将被认为是新的浏览器缓存。浏览器经会从它自己的
缓存中回收那些加载后超时的没有再请求服务器的正文。默认的最大年龄是 60 秒.最大年龄与最后修改头联合使用
会卓越的减少事物过载与服务器负载,获得超赞的响应时间 .更加深入的参数是 no init,不初始化最大年龄缓存控
制,time,根据 time 属性与内容创建的时间设置最大年龄.
Defines if the expires header will be sent in the response. Acceptable values are off for
don't sending the header, even it is set in the filter chain, on (default) for sending it if it is
set in the filter chain and time the expires information will be intialized based on the time
parameter and creation time of the content.
定义过期的头是否在响应中被发送.可选的值有 off,不发送,即使是在过滤器链表中设置它了,on(默认)发送,当在
过滤器链表中设置的时候启用,time,过期信息将会根据 time 参数与内容创建时间被初始化.
Value 'time'
The parameter time would force the CacheFilter to send the expires
header, because the value is set always. The developer must consider
that some browsers evaluate the value and will use the cached content
in the browsers cache, until the content is expired. Consequently a
flush of the cache in the web application won't update a page in the
browser cache. Hence different users may see see a different status of
page.
选项时间将会强制缓存过滤器发送过期头,应为这个是经常被使用的。开发者必须考虑一些浏览
器使用并评估这个值并用这些缓存的内容作为浏览器缓存,直到内容过期.从而 web 应用的缓
存刷出将不会更新浏览器的缓存。因此不同用户将会看到同个页面的不同状态.
Parameter: ICacheKeyProvider (NEW! Since 2.2)缓存主键提供器
Specify a class which implements the interface ICacheKeyProvider. A developer canimplement a class which provides cache keys based on the request, the servlect cache
administrator and the cache.
一个实现了 ICacheKeyProvider 接口的特定类。开发者实现这样一个类提供基于请求的缓存主键,管理对
servlet 的缓存和缓存.
Parameter: ICacheGroupsProvider (NEW! Since 2.2)缓存组提供器
Specify a class which implements the interface ICacheGroupsProvider. A developer can
implement a class which provides cache groups based on the request, the servlect cache
administrator and the cache.
一个实现接口 ICacheGroupsProvider 的类.一个开发者可以实现这个类就能够提供给予请求的缓存组,管理
servlet 缓存和缓存
Specify a class which implements the interface EntryRefreshPolicy. A developer can
implement a class which provides a different custom cache invalidation policy for a
specific cache entry. If not specified, the default policy is timed entry expiry as specified
with the time parameter described above.
定义一个实现接口 EntryRefreshPolicy 的类。开发者能够实现这个类为一个特别的缓存入口自定义缓存失效规则.
如果没有指定,默认规则是根据 time 参数描述的时间来让缓存入口过期的.
Specify HTTP method names in a comma separated list for which cacheing should be
disabled. The default value is <code>null</code> for cacheing all requests without
regarding the method name. See HttpServletRequest#getMethod, e.g.:
在以,分割的列表中定义 HTTP 方法名称就可以对他们禁用缓存。默认值是 null ,这会忽视方法名称而缓存所有请求.
参见 HttpServletRequest 的 getMethod 方法
<init-param>
<param-name>disableCacheOnMethods</param-name>
<param-value>POST,PUT,DELETE</param-value>
</init-param>
By specifying a OSCache properties file for a CacheFilter, the developer can run multiple
caches each with different configurations tailored to the requirements of the application.
In each properties file the developer has to define a unique cache.key otherwise the
default properties file is used. If the parameter is not specified, the default properties file
will be used. The file has to be put into the classpath, e.g. WEB-INF/classes.
为一个缓存过滤器定义一个 OSCache 属性文件,开发者可以为应用不同需求进行细化合理的配置并使用多个缓存。
为每个属性文件开发者必须定义一个唯一缓存主键 cache.key,否则会使用默认属性文件定义的缓存主键.这些文件需
要被放在类路径下,比如 WEB-INF/classes 下面.