改变缓存目录

<!--[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]-->
publicclass DiskPersistenceListener extends AbstractDiskPersistenceListener {
<!--[if !supportEmptyParas]--> <!--[endif]-->
    privatestaticfinallongserialVersionUID = 1L;
<!--[if !supportEmptyParas]--> <!--[endif]-->
    privatestaticfinal String CHARS_TO_CONVERT = "./// :;/"/'_?";
<!--[if !supportEmptyParas]--> <!--[endif]-->
    publicchar[] getCacheFileName(String key) { // <1> protected 改为 public
       if ((key == null) || (key.length() == 0)) {
           thrownew 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 = newchar[sb.length()];
        sb.getChars(0, fileChars.length, fileChars, 0);
        return fileChars;
    }
<!--[if !supportEmptyParas]--> <!--[endif]-->
    publicstaticvoid 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]-->
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值