kelefa  
          大千世界中,唯一缺乏的就是人類的注意力。
          日歷
          <2025年7月>
          293012345
          6789101112
          13141516171819
          20212223242526
          272829303112
          3456789
          統(tǒng)計(jì)
          • 隨筆 - 11
          • 文章 - 0
          • 評(píng)論 - 28
          • 引用 - 0

          導(dǎo)航

          常用鏈接

          留言簿(2)

          隨筆分類

          隨筆檔案

          搜索

          •  

          最新評(píng)論

          閱讀排行榜

          評(píng)論排行榜

           

          OSCache是OpenSymphony組織提供的一個(gè)J2EE架構(gòu)中Web應(yīng)用層的緩存技術(shù)實(shí)現(xiàn)方案,可以使用內(nèi)存、硬盤空間、同時(shí)使用內(nèi)存和硬盤作為緩存區(qū)靈活的緩存系統(tǒng):OSCache支持多種緩存級(jí)別,使用相當(dāng)靈活簡(jiǎn)單,在jsp中刷新緩存只要兩行代碼:


          <% @?taglib?uri = " oscache " ?prefix = " cache " %>

          < cache:flush?group = " device_types " ?scope = " application " ? />

          但是有時(shí)需要在java代碼中刷新緩存,以下這個(gè)OSCacheUtil類可以工作,但是只能在webwork環(huán)境內(nèi)調(diào)用:
          import?javax.servlet.jsp.PageContext;

          import?org.apache.log4j.Logger;
          import?com.opensymphony.oscache.base.Cache;
          import?com.opensymphony.oscache.web.ServletCacheAdministrator;
          import?com.opensymphony.webwork.ServletActionContext;

          /**
          ?*?osCache緩存工具類.
          ?*?只能在webwork環(huán)境內(nèi)調(diào)用
          ?*
          ?*?<p>Copyright:?Copyright?(c)?2005</p>
          ?*?<p>Company:?</p>
          ?*?
          @author?楊杰榮
          ?*?
          @version?1.0
          ?
          */

          public?class?OSCacheUtil
          {
          ??
          private?static?final?Logger?log?=?Logger.getLogger(?OSCacheUtil.class?);

          ??
          public?static?final?int?ALL_SCOPE?=?0;
          ??
          public?static?final?int?SESSION_SCOPE?=?PageContext.SESSION_SCOPE;
          ??
          public?static?final?int?APPLICATION_SCOPE?=?PageContext.APPLICATION_SCOPE;

          ??
          private?static?ServletCacheAdministrator?admin?=?null;

          ??
          private?OSCacheUtil()
          ??
          {
          ??}


          ??
          /**
          ???*?刷新osCache組
          ???*?
          @param?group?Cache組名
          ???*?
          @param?cacheScope?Cache范圍,只能是SESSION_SCOPE或APPLICATION_SCOPE
          ???
          */

          ??
          public?static?void?flushGroup(?String?group,?int?cacheScope?)
          ??
          {
          ????initCacheAdmin();

          ????
          if?(?cacheScope?==?SESSION_SCOPE?||?cacheScope?==?APPLICATION_SCOPE?)
          ????
          {
          ??????Cache?cache?
          =?admin.getCache(?ServletActionContext.getRequest(),
          ????????????????????????????????????cacheScope?);
          ??????cache.flushGroup(?group?);
          ????}

          ????
          else
          ????
          {
          ??????log.warn(?
          "A?cache?group?was?specified?for?flushing,?but?the?scope?wasn't?supplied?or?was?invalid"?);
          ????}

          ??}


          ??
          /**
          ???*?刷新osCache中的某個(gè)key'
          ???*?
          @param?key?String
          ???*?
          @param?cacheScope?Cache范圍,只能是SESSION_SCOPE或APPLICATION_SCOPE
          ???
          */

          ??
          public?static?void?flushKey(?String?key,?int?cacheScope?)
          ??
          {
          ????initCacheAdmin();

          ????
          if?(?cacheScope?==?SESSION_SCOPE?||?cacheScope?==?APPLICATION_SCOPE?)
          ????
          {
          ??????String?actualKey?
          =?admin.generateEntryKey(
          ??????????key,?ServletActionContext.getRequest(),?cacheScope,?
          null?);

          ??????Cache?cache?
          =?admin.getCache(?ServletActionContext.getRequest(),?cacheScope?);
          ??????cache.flushEntry(?actualKey?);
          ????}

          ????
          else
          ????
          {
          ??????log.warn(?
          "A?cache?key?was?specified?for?flushing,?but?the?scope?wasn't?supplied?or?was?invalid"?);
          ????}

          ??}


          ??
          /**
          ???*?刷新所有的osCache
          ???*?
          @param?cacheScope?Cache范圍,可以是SESSION_SCOPE,APPLICATION_SCOPE,ALL_SCOPE
          ???
          */

          ??
          public?static?void?flushAll(?int?cacheScope?)
          ??
          {
          ????initCacheAdmin();

          ????
          if?(?cacheScope?==?SESSION_SCOPE?||?cacheScope?==?APPLICATION_SCOPE?)
          ????
          {
          ??????admin.setFlushTime(?cacheScope?);
          ????}

          ????
          else
          ????
          {
          ??????admin.flushAll();
          ????}

          ??}



          ??
          private?static?void?initCacheAdmin()
          ??
          {
          ????
          if?(?admin?==?null?)
          ????
          {
          ??????admin?
          =?ServletCacheAdministrator.getInstance(?ServletActionContext.
          ??????????getServletContext()?);
          ????}

          ??}

          }
          posted @ 2006-06-29 09:32 楊杰榮 閱讀(1499) | 評(píng)論 (2)編輯 收藏
          僅列出標(biāo)題
          共2頁: 上一頁 1 2 
           
          Copyright © 楊杰榮 Powered by: 博客園 模板提供:滬江博客
          主站蜘蛛池模板: 深泽县| 越西县| 黎川县| 阳江市| 县级市| 时尚| 仙桃市| 邯郸县| 东山县| 顺平县| 新建县| 大冶市| 类乌齐县| 白沙| 大庆市| 泰来县| 大埔区| 永登县| 新闻| 衡水市| 安泽县| 恭城| 紫金县| 聊城市| 嘉兴市| 镇赉县| 克什克腾旗| 班玛县| 化隆| 沿河| 安陆市| 四平市| 独山县| 新民市| 五莲县| 綦江县| 洛浦县| 冀州市| 大宁县| 油尖旺区| 广宗县|