• ehcache缓存使用


    CacheUtils.java //工具类

    保存cache缓存:

    CacheUtils.put(CacheUtils.SIGN_CACHE, childid + "_" + mNum, signatureData);

     取缓存:

    //public static Object get(String cacheName, String key)
    Object signObj = CacheUtils.get(CacheUtils.SIGN_CACHE, childVaccinaterecord.getChildid() + "_" + childVaccinaterecord.getVaccineid());
    String signStr = (String) signObj;//再将Object对象强转为字符串

     删除缓存:

    CacheUtils.remove(CacheUtils.SIGN_CACHE, childVaccinaterecord.getChildid() + "_" + childVaccinaterecord.getNid().substring(0, 2));



    /**
     * Copyright &copy; 2012-2014 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
     */
    package com.thinkgem.jeesite.common.utils;
    
    import net.sf.ehcache.Cache;
    import net.sf.ehcache.CacheManager;
    import net.sf.ehcache.Element;
    
    /**
     * Cache工具类
     * @author ThinkGem
     * @version 2013-5-29
     */
    public class CacheUtils {
        
        private static CacheManager cacheManager = ((CacheManager)SpringContextHolder.getBean("cacheManager"));
    
        private static final String SYS_CACHE = "sysCache";
        public static final String SIGN_CACHE = "signCache";
        public static final String COLD_CACHE ="coldCache";
    
        /**
         * 获取SYS_CACHE缓存
         * @param key
         * @return
         */
        public static Object get(String key) {
            return get(SYS_CACHE, key);
        }
        
        /**
         * 写入SYS_CACHE缓存
         * @param key
         * @return
         */
        public static void put(String key, Object value) {
            put(SYS_CACHE, key, value);
        }
        
        /**
         * 从SYS_CACHE缓存中移除
         * @param key
         * @return
         */
        public static void remove(String key) {
            remove(SYS_CACHE, key);
        }
        
        /**
         * 获取缓存
         * @param cacheName
         * @param key
         * @return
         */
        public static Object get(String cacheName, String key) {
            Element element = getCache(cacheName).get(key);
            return element==null?null:element.getObjectValue();
        }
    
        /**
         * 写入缓存
         * @param cacheName
         * @param key
         * @param value
         */
        public static void put(String cacheName, String key, Object value) {
            Element element = new Element(key, value);
            getCache(cacheName).put(element);
        }
    
        /**
         * 从缓存中移除
         * @param cacheName
         * @param key
         */
        public static void remove(String cacheName, String key) {
            getCache(cacheName).remove(key);
        }
        
        /**
         * 获得一个Cache,没有则创建一个。
         * @param cacheName
         * @return
         */
        private static Cache getCache(String cacheName){
            Cache cache = cacheManager.getCache(cacheName);
            if (cache == null){
                cacheManager.addCache(cacheName);
                cache = cacheManager.getCache(cacheName);
                cache.getCacheConfiguration().setEternal(true);
            }
            return cache;
        }
    
        public static CacheManager getCacheManager() {
            return cacheManager;
        }
        
    }

    签字缓存保存位置:

  • 相关阅读:
    proc文件系统的简介
    linux获取文件属性(API)
    busybox inittab文件分析
    设计模式之Builder模式
    This用法
    以 280W 数据为依据。对比SQL2008 表分区前和分区后的 T_SQL 效率
    jquery数据验证插件(自制,简单,练手)
    C# 每天温习一点(IEnumerable<TSource>)
    多线程应用扫盲(如何简单使用多线程)
    之前做web性能优化的一些个人心得
  • 原文地址:https://www.cnblogs.com/banxian-yi/p/10790015.html
Copyright © 2020-2023  润新知