`

oscache tag

阅读更多

 

The tags are:

  • cache - The main caching tag
  • usecached - A nested tag to force using a cached version.
  • flush - To flush caches programmatically.
  • addgroup - It allows a single group name to be dynamically added to a cached block. This tag must be nested inside <cache:cache/>.
  • addgroups - It allows a comma-delimited list of group names to be dynamically added to a cached block. This tag must be nested inside <cache:cache/>.
Tag Legend
  • For all listed attributes, req means it that attribute is required and any value in [ ] is a default value. All attributes can accept runtime expressions.
  • From the title of the tag you can see whether or not the tag has a body:
    • <tag></tag> tags always have a body
    • <tag /> does not have a body
    • <tag /></tag> can have a body or not depending on the circumstances.

<cache></cache>

Description:

This is the main tag of OSCache. The body of the tag will be cached according to the attributes specified. The first time a cache is used the body content is executed and cached.

Each subsequent time the tag is run, it will check to see if the cached content is stale. Content is considered stale due to one (or more) of the following being true:

  • The cached body content has been in the cache for longer than the time specified by the time or duration attribute.
  • The cron attribute matches a date/time that is more recent than the time the body content was originally cached.
  • The scope the body content is cached in was flushed since the content was originally cached.

If the cached body content is stale, the tag will execute the body again and recache the new body content. Otherwise it will serve the cached content and the body will be skipped (resulting in a large speed increase).

Attributes:

  • key - [The request URI + query string] - The cache key, any string. This should be unique for the given scope since duplicate keys will map to the same cache entry. The default value uses an escaped version of the URI and query string of the current page.
    It is possible to specify multiple cache tags in the same page without specifying keys - in this situation an index is appended to the key of subsequent tags. However this usage is discouraged since if the flow of the page is inconsistent, or cache tags are nested, the indicies will potentially change each time the page is executed, resulting in seemingly jumbled cache entries.
  • scope - [application] - The scope of this cache (valid values are "application" and "session").
  • time - [3600] The amount of time to cache this content for (in seconds). (Default is 3600 seconds, one hour). Supplying a negative value for this attribute means that the content never expires.
  • duration - [] - The duration of this cache (this attribute is an alternative to time). duration can be specified using Simple Date Format or ISO-8601 date format.
  • cron - [] - A cron expression that determines when this cached 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 

    http://stonedeng.iteye.com/blog/1378229

    .
  • refresh - [false] - A boolean. If true, the cache will be refreshed regardless of whether it is considered stale or not. This enables you to decide at runtime whether or not to rebuild the content.
  • mode - [] - Setting this to "silent" will prevent the body of the tag from being written to the output stream. This may be useful if you want to preload the cache with content without actually displaying that content to the user.
  • groups - [] - A comma-delimited list of group names can be provided. This allows cache entries to be grouped according to your needs. Grouping is useful when you have cached content that depends on other parts of your application or data - when that dependency changes, flushing the relevant group will cause all cache entries in that group to be expired.
  • language - [] - The ISO-639 language code to distinguish different content cached under an otherwise identical key. This is useful on a multilingual site where the same JSP code is used to render content in different languages depending on the current user's preferences.
  • refreshpolicyclass - [] - A fully-qualified classname that extends com.opensymphony.oscache.web.WebEntryRefreshPolicy. This allows you to programmatically determine whether cached content should be exipired.
  • refreshpolicyparam - [] - Any arbitrary parameters that you need to pass through to the refreshpolicyclass. Specifying this attribute without specifying a refreshpolicyclass will have no effect.
    Examples
    This will cache the JSP content using the current URI as a key (which means this must be the only cache tag on the page to work).
    
        <cache:cache>
             ... some jsp content ...
        </cache:cache>
    
        This will cache the content with a constant key in the user's session scope. Any page that uses this key will access one shared cache.
    
        <cache:cache key="foobar" scope="session">
             ... some jsp content ...
        </cache:cache>
    
        This will cache the content with a programmatic key (here a product ID) for 30 minutes. It will also refresh if the variable needRefresh 
    is true.
    
        <cache:cache key="<%= product.getId() %>" time="1800" refresh="<%= needRefresh %>">
             ... some jsp content ...
        </cache:cache>
    
        This will cache the content with a programmatic key, expiring it every morning at 2am. It will also refresh if the variable needRefresh 
    is true.
    
        <cache:cache key="<%= product.getId() %>" cron="0 2 * * *" refresh="<%= needRefresh %>">
             ... some jsp content ...
        </cache:cache>
    
        Suppose we had a dynamic list of categories that we pull from a database, and we also store currency exchange rates that get updated 
    occasionally by calling a webservice. Suppose also that we have some content that displays information about both the categories and the 
    current exchange rate values. The following example caches the body content and assigns it to two cache groups, "currencyData" and 
    "categoryList". When the exchange rates or the category list is updated, the appropriate group can be flushed causing this content (along 
    with any other content associated with that group) to be exipired and then rebuilt the next time the page is processed:
    
        <cache:cache key="<%= product.getId() %>" time="-1" group="currencyData, categories">
             ... display category list ...
             ... display currency information ...
        </cache:cache>

<usecached />

Description:

This tag is nested within a <cache> tag and tells its parent whether or not to use the cached version.

Attributes:

  • use - [true] - A boolean that tells the tag whether or not to use the cached version. (true = use cached version). This is useful for
    programmatic control of the cache.
    Example
    This is a good example of error tolerance. If an exception occurs, the cached version of this content will be output instead.
    
        <cache:cache>
             <% try { %>
             ... some jsp content ...
             <% } catch (Exception e) { %>
                  <cache:usecached />
             <% } %>
        </cache:cache>

<flush />

Description:

This tag is used to flush caches at runtime. It is especially useful because it can be coded into the administration section of your site so that admins can decide when to flush the caches.

Attributes:

  • scope - [all] - This decides what scope will be flushed. Valid values are "application", "session" and null. A null scope will flush all caches, regardless of their scope.
  • key - [] - When a key and a scope are both given, just that single cache entry will be marked to be flushed. When it is next accessed, it will be refreshed. It is not valid to specify a key without a scope.
  • group - [] - Specifying a group will cause all cache entries in the group to be flushed. It is not valid to specify a group without a scope.
  • pattern - [] - Any keys that contain this string will be flushed from the specified scope. It is not valid to specify a pattern without a scope. (Note: pattern flushing has been deprecated - you are encouraged to use the grouping functionality instead. It is more flexible and provides better performance.)
  • language - [] - The ISO-639 language code to distinguish different content cached under an otherwise identical key. This is useful on a multilingual site where the same JSP code is used to render content in different languages depending on the current user's preferences.
Example
This will flush the application scope.

    <cache:flush scope="application" />

    This will flush the cache entry with key "foobar" in the session scope.

    <cache:flush scope="session" key="foobar" />

    This will flush all cache entries in the "currencyData" group from the application scope.

    <cache:flush scope="application" group="currencyData" />

<addgroup />

Description:

This tag must be nested inside a <cache:cache/> tag. It allows a single group name to be dynamically added to a cached block. It is useful when the group a cached block should belong to are unknown until the block is actually rendered. As each group is 'discovered', this tag can be used to add the group to the block's group list.

Attributes:

  • group - req - The name of the group to add the enclosing cache block to.
Example
This will add the cache block with the key 'test1' to groups 'group1' and 'group2'.

    <cache:cache key="test1">
         <cache:addgroup group="group1" />
         ... some jsp content ...
         <cache:addgroup group="group2" />
         ... some more jsp content ...
    </cache:cache>

<addgroups /> (New! Since 2.3)

Description:

This tag must be nested inside a <cache:cache/> tag. It allows a comma-delimited list of groups names to be dynamically added to a cached block with a single tag statement. As a group list is 'discovered', this tag can be used to add the groups to the block's group list.

Attributes:

  • groups - req - The comma-delimited list of groups names to add the enclosing cache block to.
Example
This will add the cache block with the key 'test1' to groups 'group1' and 'group2'.

    <cache:cache key="test1">
         ... some jsp content ...
         <cache:addgroups groups="group1,group2" />
         ... some jsp content ...
    </cache:cache>

 

分享到:
评论

相关推荐

    OSCache需要的包

    `oscache.tld` 文件是 Tag Library Descriptor (TLD) 文件,它是JSP 2.0规范的一部分,用于定义自定义标签库。在这个特定的案例中,`oscache.tld` 提供了关于OSCache JSP标签的元数据,如标签的名称、属性、行为等,...

    oscache缓存中间件

    OSCache标记库由OpenSymphony设计,它是一种开创性的缓存方案,它提供了在现有JSP页面之内实现内存缓存的功能。OSCache是个一个被广泛采用的高性能的J2EE缓存框架,OSCache还能应用于任何Java应用程序的普通的缓存...

    oscache代码最新

    oscache,java技术,数据缓存 OSCache can be used as a ...OSCache's tag library and the caching filter for dynamic binary content, like PDFs or images, require a Servlet 2.3 / JSP 1.2 compliant container.

    java常见的Jar包

    2. **jstl.jar**:全称JavaServer Pages Standard Tag Library,即JSP标准标签库,它是JavaWeb开发中的一个重要组件。`jstl.jar`提供了一系列预定义的标签,用于简化JSP页面的编写,使代码更加清晰、易读。JSTL支持...

    springMVC配置

    4. `oscache.tld`:TLD(Tag Library Descriptor)文件是用于定义自定义标签库的描述文件,这里可能是OSCache提供的JSP标签库,用于在视图层处理缓存相关的操作。 5. `applicationContext.xml`:这是Spring的主配置...

    J2EE开发之常用开源项目小记

    - **JSTL**:JavaServer Pages Standard Tag Library,用于增强JSP页面的功能,提供了许多内置标签,被认为是最快的JSP标签库之一。 - **富客户端库**:如DOJO Widgets、YUI、FCKEditor和Coolest日历控件,这些库...

    SSH开发SSH开发SSH开发SSH开发

    - `oscache-2.3.jar`:OSCache是开源的缓存解决方案,可以提高应用性能,减少对数据库的访问。 - `mysql-connector-java-5.1.6-bin.jar`:MySQL的Java连接器,用于连接Java应用到MySQL数据库。 - `joddform.jar`...

    J2EE常用开源项目

    - **Display Tag**和**Extreme Table**:两者都能生成视图层的表格,支持导出和对Spring的集成。Extreme Table在功能上更强大,支持Ajax,并有中文文档。 5. **缓存技术**: - **OSCache**:OpenSymphony组织提供...

    J2EE开发之常用开源项目介绍

    JSTL(JavaServer Pages Standard Tag Library)则提供了一系列标准标签库,简化了JSP页面的开发过程。 - **前端框架**:如YUI、Dojo等前端框架提供了丰富的组件库,能够快速构建出美观且功能丰富的用户界面。 - **...

    SSH 中jar包说明

    - **用途**:通常指JSTL(JavaServer Pages Standard Tag Library)的实现。 - **作用**:提供了标准标签库,简化了JSP页面的开发过程。 #### 37. **swarmcache-1.0rc2.jar** - **用途**:SwarmCache是一个分布式的...

Global site tag (gtag.js) - Google Analytics