一.ehcache主要是對(duì)數(shù)據(jù)庫(kù)訪問的緩存,相同的查詢語(yǔ)句只需查詢一次數(shù)據(jù)庫(kù),
從而提高了查詢的速度,使用spring的AOP可以很容易實(shí)現(xiàn)這一功能.
http://ehcache.sourceforge.net/
ehcache.xml
<cache name="sampleCache1"
maxElementsInMemory="10000"
eternal="false"
timeToIdleSeconds="300"
timeToLiveSeconds="600"
overflowToDisk="true"
/>
org.springframework.cache.ehcache.EhCacheManagerFactoryBean
org.springframework.cache.ehcache.EhCacheFactoryBean
org.springframework.aop.support.RegexpMethodPointcutAdvisor
二. oscache 主要是對(duì)頁(yè)面的緩存,可以整頁(yè)或者指定網(wǎng)頁(yè)某一部分緩存,同時(shí)
指定他的過期時(shí)間,這樣在此時(shí)間段里面訪問的數(shù)據(jù)都是一樣的
1.log4j-1.2.8.jar,oscache-2.3.2.jar,commons-logging.jar,jgroups-all.jar
2.拷貝cach\etc\下的oscache.tld,oscache.properties 到WEB-INF\classes
3.web.xml
<taglib><taglib-uri>oscache</taglib-uri><taglib-location>/WEB-INF/classes/ oscache.tld</taglib-location></taglib>
<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>60</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>
http://www.opensymphony.com/oscache/download.html下載Oscache的最新版本
可以使用內(nèi)存、硬盤空間、同時(shí)使用內(nèi)存和硬盤或者提供自己的其他資源(需要自己提供適配器)作為緩存區(qū)。
- 使用內(nèi)存作為緩存區(qū)將可以提供更好的性能
- 使用硬盤作為緩存區(qū)可以在服務(wù)器重起后迅速恢復(fù)緩存內(nèi)容
- 同時(shí)使用內(nèi)存和硬盤作為緩存區(qū)則可以減少對(duì)內(nèi)存的占用