kelefa  
          大千世界中,唯一缺乏的就是人類的注意力。
          日歷
          <2025年5月>
          27282930123
          45678910
          11121314151617
          18192021222324
          25262728293031
          1234567
          統計
          • 隨筆 - 11
          • 文章 - 0
          • 評論 - 28
          • 引用 - 0

          導航

          常用鏈接

          留言簿(2)

          隨筆分類

          隨筆檔案

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

           

          OSCache是OpenSymphony組織提供的一個J2EE架構中Web應用層的緩存技術實現方案,可以使用內存、硬盤空間、同時使用內存和硬盤作為緩存區靈活的緩存系統:OSCache支持多種緩存級別,使用相當靈活簡單,在jsp中刷新緩存只要兩行代碼:


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

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

          但是有時需要在java代碼中刷新緩存,以下這個OSCacheUtil類可以工作,但是只能在webwork環境內調用:
          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環境內調用
          ?*
          ?*?<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中的某個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 楊杰榮 閱讀(1489) | 評論 (2)編輯 收藏
          僅列出標題
          共2頁: 上一頁 1 2 
           
          Copyright © 楊杰榮 Powered by: 博客園 模板提供:滬江博客
          主站蜘蛛池模板: 华亭县| 偃师市| 松阳县| 车致| 五华县| 泸西县| 克拉玛依市| 三都| 南宫市| 布尔津县| 富蕴县| 米脂县| 梅州市| 化州市| 尉氏县| 长治市| 广宁县| 呼和浩特市| 秦皇岛市| 星座| 阜南县| 富宁县| 吕梁市| 吉安县| 浪卡子县| 沁水县| 兖州市| 鄯善县| 土默特左旗| 青川县| 隆昌县| 汕头市| 九龙县| 武邑县| 玛沁县| 泊头市| 河北区| 柯坪县| 太白县| 黎平县| 东莞市|