OSCache 的JSP页面缓冲技术

本文介绍了如何使用OSCache进行缓存配置。主要内容包括下载安装、配置web.xml、使用JSP标签实现页面缓存等步骤。同时提供了刷新缓存及缓存参数详细说明。
1 下载地址 http://www.opensymphony.com/oscache/
2 把下载的jar 加入到你的build path 里面。 建议直接放到 tomcat/shared/lib 目录下面
3 在 web.xml 里面增加配置
  1. <taglib>   
  2.         <taglib-uri>oscache</taglib-uri>   
  3.         <taglib-location>/WEB-INF/classes/oscache.tld</taglib-location>   
  4. </taglib>  
        <taglib>
                <taglib-uri>oscache</taglib-uri>
                <taglib-location>/WEB-INF/classes/oscache.tld</taglib-location>
        </taglib>


4 在你的jsp 页面里增加如下标签
  1. <%@ taglib uri="http://www.opensymphony.com/oscache" prefix="cache"%>  
<%@ taglib uri="http://www.opensymphony.com/oscache" prefix="cache"%>


5 在需要缓冲的部分,采用如下标签

  1.     
  2. <cache:cache key="myPageCachekey" groups="myDefaultGroup" scope="application" time="1800">   
  3. 。。。 这中间是你要缓冲的内容   
  4. </cache:cache>  
 
<cache:cache key="myPageCachekey" groups="myDefaultGroup" scope="application" time="1800">
。。。 这中间是你要缓冲的内容
</cache:cache>


6 刷新缓冲
  1. <cache:flush scope="application" group="myDefaultGroup" />  
<cache:flush scope="application" group="myDefaultGroup" />



其中的
key - [默认为请求的 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.
缓冲的key,可以是任何的字符串。在一个范围内是唯一的,因为相同的key代表了相同的缓冲入口。默认使用请求的URI和请求的字符串(问号后面的部分)

scope - [application] - The scope of this cache (valid values are "application" and "session").
范围,有application和session, 默认为 application

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.
缓冲内容的时间(秒)。默认为1小时,3600秒,如果为-1则内容你永远不过期


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.
另外一种设置缓冲时间的方法。可以用简单日期格式或者ISO-8601的日期格式

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 Cron Expressions to read more about this attribute.
定时刷新的设置。可以在指定的时间和周期进行刷新。

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.
设置为[silent]可以让你提前把内容读取,但不会输出到。


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.
传递给刷新策略类的参数
内容概要:本文系统介绍了算术优化算法(AOA)的基本原理、核心思想及Python实现方法,并通过图像分割的实际案例展示了其应用价值。AOA是一种基于种群的元启发式算法,其核心思想来源于四则运算,利用乘除运算进行全局勘探,加减运算进行局部开发,通过数学优化器加速函数(MOA)和数学优化概率(MOP)动态控制搜索过程,在全局探索与局部开发之间实现平衡。文章详细解析了算法的初始化、勘探与开发阶段的更新策略,并提供了完整的Python代码实现,结合Rastrigin函数进行测试验证。进一步地,以Flask框架搭建前后端分离系统,将AOA应用于图像分割任务,展示了其在实际工程中的可行性与高效性。最后,通过收敛速度、寻优精度等指标评估算法性能,并提出自适应参数调整、模型优化和并行计算等改进策略。; 适合人群:具备一定Python编程基础和优化算法基础知识的高校学生、科研人员及工程技术人员,尤其适合从事人工智能、图像处理、智能优化等领域的从业者;; 使用场景及目标:①理解元启发式算法的设计思想与实现机制;②掌握AOA在函数优化、图像分割等实际问题中的建模与求解方法;③学习如何将优化算法集成到Web系统中实现工程化应用;④为算法性能评估与改进提供实践参考; 阅读建议:建议读者结合代码逐行调试,深入理解算法流程中MOA与MOP的作用机制,尝试在不同测试函数上运行算法以观察性能差异,并可进一步扩展图像分割模块,引入更复杂的预处理或后处理技术以提升分割效果。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值