注册 | 登录 忘记密码? 51cto首页 | 博客 | 论坛 | 招聘
热点文章 SWAT—Samba WEB管理..
 帮助

改变 OsCache 缓存文件存储目录


2007-03-12 09:55:25
版权声明:原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。否则将追究法律责任。http://maomao.blog.51cto.com/115985/20227
<!--[if !supportEmptyParas]--> <!--[endif]-->
一、修改 DiskPersistenceListener.java 文件:
<!--[if !supportEmptyParas]--> <!--[endif]-->
package com.jh.xh.hibernate.oscache;
<!--[if !supportEmptyParas]--> <!--[endif]-->
import com.opensymphony.oscache.plugins.diskpersistence.AbstractDiskPersistenceListener;
<!--[if !supportEmptyParas]--> <!--[endif]-->
public class DiskPersistenceListener extends AbstractDiskPersistenceListener {
<!--[if !supportEmptyParas]--> <!--[endif]-->
    private static final long serialVersionUID = 1L;
<!--[if !supportEmptyParas]--> <!--[endif]-->
    private static final String CHARS_TO_CONVERT = "./\\ :;\"\'_?";
<!--[if !supportEmptyParas]--> <!--[endif]-->
    public char[] getCacheFileName(String key) { // <1> protected 改为 public
       if ((key == null) || (key.length() == 0)) {
           throw new IllegalArgumentException("Invalid key '" + key
                  + "' specified to getCacheFile.");
       }
<!--[if !supportEmptyParas]--> <!--[endif]-->
      char[] chars = key.toCharArray();
<!--[if !supportEmptyParas]--> <!--[endif]-->
        StringBuffer sb = new StringBuffer(chars.length + 10);
<!--[if !supportEmptyParas]--> <!--[endif]-->
       for (int i = 0; i < chars.length; i++) {
           char c = chars[i];
           int pos = CHARS_TO_CONVERT.indexOf(c);
<!--[if !supportEmptyParas]--> <!--[endif]-->
           if (pos >= 0) {
               sb.append('_');
               sb.append(i);
           } else {
               sb.append(c);
           }
           if (i % 3 == 2) {    // <2> 添加此行代码,每三个字符做为目录名;
               sb.append('/');
           }
       }
        sb.append('0');
      char[] fileChars = new char[sb.length()];
        sb.getChars(0, fileChars.length, fileChars, 0);
        return fileChars;
    }
<!--[if !supportEmptyParas]--> <!--[endif]-->
    public static void main(String str[]) {
        System.out.println(new DiskPersistenceListener().getCacheFileName("12341dfkaklakasdfadklskadllkklasdf"));
<!--[if !supportEmptyParas]--> <!--[endif]-->
    }
}
<!--[if !supportEmptyParas]--> <!--[endif]-->
<!--[if !supportEmptyParas]--> <!--[endif]-->
二、修改 oscache.properties 文件:
cache.persistence.class=com.jh.xh.hibernate.oscache.DiskPersistenceListener
<!--[if !supportEmptyParas]--> <!--[endif]-->

本文出自 “maomao” 博客,请务必保留此出处http://maomao.blog.51cto.com/115985/20227





    文章评论
 
 

发表评论

昵   称:
验证码:  点击图片可刷新验证码  博客过2级,无需填写验证码
内   容: