欧美三区_成人在线免费观看视频_欧美极品少妇xxxxⅹ免费视频_a级毛片免费播放_鲁一鲁中文字幕久久_亚洲一级特黄

oscache源代碼閱讀(四) -- JSP/Servlet緩存Cach

系統(tǒng) 2411 0

oscache對于jsp/servlet的緩存是使用Filter來實現的,對應的類是 com.opensymphony.oscache.web.filter.CacheFilter,既然是Filter那么要看的自然主要有三個方 法:init、doFilter和destroy,這里#destroy()并沒有具體實現,只關注前兩個即可,首先看一下#init()方法,

???? public ? void ?init(FilterConfig?filterConfig)? {
????????config?
= ?filterConfig;

????????log.info(
" OSCache:?Initializing?CacheFilter?with?filter?name? " ? + ?config.getFilterName());

????????
// ?此變量用于防治請求被重復的緩存
????????requestFiltered? = ?REQUEST_FILTERED? + ?config.getFilterName();
????????log.info(
" Request?filter?attribute?is? " ? + ?requestFiltered);

????????
// ?讀取配置文件
????????Properties?props? = ? null ;
????????
try ? {
????????????
// ?首先按照Filter參數指定的地方讀取配置文件,否則讀取默認位置的
????????????String?propertiesfile? = ?config.getInitParameter( " oscache-properties-file " );

????????????
if ?(propertiesfile? != ? null ? && ?propertiesfile.length()? > ? 0 )? {
????????????????props?
= ?Config.loadProperties(propertiesfile,
????????????????????????
" CacheFilter?with?filter?name?' " ? + ?config.getFilterName()? + ? " ' " );
????????????}

????????}
? catch ?(Exception?e)? {
????????????log.info(
" OSCache:?Init?parameter?'oscache-properties-file'?not?set,?using?default. " );
????????}


????????
// ?實例化ServletCacheAdministrator,ServletCacheAdministrator只有一個實例,這里需要關注一下
????????admin? = ?ServletCacheAdministrator.getInstance(config.getServletContext(),?props);

????????
// ?緩存超時時間
????????String?timeParam? = ?config.getInitParameter( " time " );
????????
if ?(timeParam? != ? null )? {
????????????
try ? {
????????????????setTime(Integer.parseInt(timeParam));
????????????}
? catch ?(NumberFormatException?nfe)? {
????????????????log.error(
" OSCache:?Unexpected?value?for?the?init?parameter?'time',?defaulting?to?one?hour.?Message= "
????????????????????????
+ ?nfe.getMessage());
????????????}

????????}


????????
// ?緩存范圍
????????String?scopeParam? = ?config.getInitParameter( " scope " );
????????
if ?(scopeParam? != ? null )? {
????????????
if ?( " session " .equalsIgnoreCase(scopeParam))? {
????????????????setCacheScope(PageContext.SESSION_SCOPE);
????????????}
? else ? if ?( " application " .equalsIgnoreCase(scopeParam))? {
????????????????setCacheScope(PageContext.APPLICATION_SCOPE);
????????????}
? else ? {
????????????????log.error(
" OSCache:?Wrong?value?' " ? + ?scopeParam
????????????????????????
+ ? " '?for?init?parameter?'scope',?defaulting?to?'application'. " );
????????????}


????????}


????????
// ?利用"計劃任務"表達式來處理超時時間
????????setCron(config.getInitParameter( " cron " ));

????????
// ?是否處理include
????????String?fragmentParam? = ?config.getInitParameter( " fragment " );
????????
if ?(fragmentParam? != ? null )? {
????????????
if ?( " no " .equalsIgnoreCase(fragmentParam))? {
????????????????setFragment(FRAGMENT_NO);
????????????}
? else ? if ?( " yes " .equalsIgnoreCase(fragmentParam))? {
????????????????setFragment(FRAGMENT_YES);
????????????}
? else ? if ?( " auto " .equalsIgnoreCase(fragmentParam))? {
????????????????setFragment(FRAGMENT_AUTODETECT);
????????????}
? else ? {
????????????????log.error(
" OSCache:?Wrong?value?' " ? + ?fragmentParam
????????????????????????
+ ? " '?for?init?parameter?'fragment',?defaulting?to?'auto?detect'. " );
????????????}

????????}


????????
// ?是否處理URL里包括session?id的請求
????????String?nocacheParam? = ?config.getInitParameter( " nocache " );
????????
if ?(nocacheParam? != ? null )? {
????????????
if ?( " off " .equalsIgnoreCase(nocacheParam))? {
????????????????nocache?
= ?NOCACHE_OFF;
????????????}
? else ? if ?( " sessionIdInURL " .equalsIgnoreCase(nocacheParam))? {
????????????????nocache?
= ?NOCACHE_SESSION_ID_IN_URL;
????????????}
? else ? {
????????????????log.error(
" OSCache:?Wrong?value?' " ? + ?nocacheParam
????????????????????????
+ ? " '?for?init?parameter?'nocache',?defaulting?to?'off'. " );
????????????}

????????}


????????
// ?是否處理寫入到response中的header屬性Last-Modified
????????String?lastModifiedParam? = ?config.getInitParameter( " lastModified " );
????????
if ?(lastModifiedParam? != ? null )? {
????????????
if ?( " off " .equalsIgnoreCase(lastModifiedParam))? {
????????????????lastModified?
= ?LAST_MODIFIED_OFF;
????????????}
? else ? if ?( " on " .equalsIgnoreCase(lastModifiedParam))? {
????????????????lastModified?
= ?LAST_MODIFIED_ON;
????????????}
? else ? if ?( " initial " .equalsIgnoreCase(lastModifiedParam))? {
????????????????lastModified?
= ?LAST_MODIFIED_INITIAL;
????????????}
? else ? {
????????????????log.error(
" OSCache:?Wrong?value?' " ? + ?lastModifiedParam
????????????????????????
+ ? " '?for?init?parameter?'lastModified',?defaulting?to?'initial'. " );
????????????}

????????}


????????
// ?是否處理寫入到response中的header屬性Expires
????????String?expiresParam? = ?config.getInitParameter( " expires " );
????????
if ?(expiresParam? != ? null )? {
????????????
if ?( " off " .equalsIgnoreCase(expiresParam))? {
????????????????setExpires(EXPIRES_OFF);
????????????}
? else ? if ?( " on " .equalsIgnoreCase(expiresParam))? {
????????????????setExpires(EXPIRES_ON);
????????????}
? else ? if ?( " time " .equalsIgnoreCase(expiresParam))? {
????????????????setExpires(EXPIRES_TIME);
????????????}
? else ? {
????????????????log.error(
" OSCache:?Wrong?value?' " ? + ?expiresParam
????????????????????????
+ ? " '?for?init?parameter?'expires',?defaulting?to?'on'. " );
????????????}

????????}


????????
// ?是否處理寫入到response中的header屬性Cache-Control
????????String?cacheControlMaxAgeParam? = ?config.getInitParameter( " max-age " );
????????
if ?(cacheControlMaxAgeParam? != ? null )? {
????????????
if ?(cacheControlMaxAgeParam.equalsIgnoreCase( " no?init " ))? {
????????????????setCacheControlMaxAge(MAX_AGE_NO_INIT);
????????????}
? else ? if ?(cacheControlMaxAgeParam.equalsIgnoreCase( " time " ))? {
????????????????setCacheControlMaxAge(MAX_AGE_TIME);
????????????}
? else ? {
????????????????
try ? {
????????????????????setCacheControlMaxAge(Long.parseLong(cacheControlMaxAgeParam));
????????????????}
? catch ?(NumberFormatException?nfe)? {
????????????????????log.error(
" OSCache:?Unexpected?value?for?the?init?parameter?'max-age',?defaulting?to?'60'.?Message= "
????????????????????????????
+ ?nfe.getMessage());
????????????????}

????????????}

????????}


????????
// ?ICacheKeyProvider的實例,用于創(chuàng)建緩存的key
????????ICacheKeyProvider?cacheKeyProviderParam? = ?(ICacheKeyProvider)?instantiateFromInitParam(
????????????????
" ICacheKeyProvider " ,?ICacheKeyProvider. class ,? this .getClass().getName());
????????
if ?(cacheKeyProviderParam? != ? null )? {
????????????setCacheKeyProvider(cacheKeyProviderParam);
????????}


????????
// ?ICacheGroupsProvider的實例,用于創(chuàng)建緩存的group名字
????????ICacheGroupsProvider?cacheGroupsProviderParam? = ?(ICacheGroupsProvider)?instantiateFromInitParam(
????????????????
" ICacheGroupsProvider " ,?ICacheGroupsProvider. class ,? this .getClass().getName());
????????
if ?(cacheGroupsProviderParam? != ? null )? {
????????????setCacheGroupsProvider(cacheGroupsProviderParam);
????????}


????????
// ?EntryRefreshPolicy的實例,用于指定緩存過期策略
????????EntryRefreshPolicy?expiresRefreshPolicyParam? = ?(EntryRefreshPolicy)?instantiateFromInitParam(
????????????????
" EntryRefreshPolicy " ,?EntryRefreshPolicy. class ,?ExpiresRefreshPolicy. class .getName());
????????
if ?(expiresRefreshPolicyParam? != ? null )? {
????????????setExpiresRefreshPolicy(expiresRefreshPolicyParam);
????????}
? else ? {
????????????setExpiresRefreshPolicy(
new ?ExpiresRefreshPolicy(time));
????????}


????????
// ?指定哪些請求方式不去緩存,如GET,POST等
????????String?disableCacheOnMethodsParam? = ?config.getInitParameter( " disableCacheOnMethods " );
????????
if ?(StringUtil.hasLength(disableCacheOnMethodsParam))? {
????????????disableCacheOnMethods?
= ?StringUtil.split(disableCacheOnMethodsParam,? ' , ' );
????????}


????}


這個方法主要是對Filter的init-param的載入還有緩存管理器類實例的創(chuàng)建(里面會包括一個Application Scope的Cache的創(chuàng)建還有oscache配置文件的讀取)。其中的這句調用時需要關注一下的,admin = ServletCacheAdministrator.getInstance(config.getServletContext(), props),也就是ServletCacheAdministrator類實例的創(chuàng)建。

???? public ? synchronized ? static ?ServletCacheAdministrator?getInstance(ServletContext?context,?Properties?p)? {
????????
// ?Cache在ServletContext中的屬性名
????????String?adminKey? = ? null ;
????????
if ?(p? != ? null )? {
????????????
// ?這里是oscache配置文件中的cache.key屬性
????????????adminKey? = ?p.getProperty(CACHE_KEY_KEY);
????????}

????????
if ?(adminKey? == ? null )? {
????????????adminKey?
= ?DEFAULT_CACHE_KEY;
????????}

????????
// ?ServletCacheAdministrator在ServletContext中的鍵值要加上"_admin"這個后綴
????????adminKey? += ?CACHE_ADMINISTRATOR_KEY_SUFFIX;

????????
// ?先嘗試在ServletContext中找Cache,當然,第一次初始化時是不會找到的
????????ServletCacheAdministrator?adm
2
4
分享到:
評論

oscache源代碼閱讀(四) -- JSP/Servlet緩存CacheFilter


更多文章、技術交流、商務合作、聯(lián)系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯(lián)系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦?。?!

發(fā)表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 美女国产网站 | 欧美aaaa视频 | 日本久久高清视频 | 国产日韩一区二区 | 亚洲国产精品久久婷婷 | 久久亚洲一区二区 | 免费视频精品一区二区 | 亚洲欧美日韩三级 | 亚在线 | 在线观看免费国产视频 | 日本黄视频在线观看 | 亚洲专区在线 | 国产精品高清在线观看 | 99久久精品国产一区二区三区 | 日本高清色惰www在线视频 | 日韩欧美在线中文字幕 | 免费高清seyeye在线视频观看 | 99在线免费观看 | 日韩电影在线看 | 久久综合九色综合97欧美 | 欧美日韩一区二区在线 | 高清一区二区 | 欧美 亚洲 另类 激情 另类 | 免费观看欧美一级片 | 国产精品久久久久久久久免费相片 | 浮力影院最新网址 | 国产精品视频999 | 日本福利一区二区 | 欧美一区免费 | 久久视频这里只精品3国产 色偷偷偷 | 亚洲国产精品第一页 | 欧美成人午夜剧场 | 丁香成人影院 | 琪琪五月天综合婷婷 | 在线视频se | 成人一区二区三区四区 | 国产成人免费高清激情视频 | jizz国产丝袜18老师女人 | 国产中文字幕在线观看 | 一级福利| 日本不卡在线一区二区三区视频 |