zoukankan      html  css  js  c++  java
  • 我的ehcache笔记

    我的EhcacheUtils类:

    package com.shinho.bi.utils;
    
    import org.ehcache.CacheManager;
    import org.ehcache.config.builders.CacheConfigurationBuilder;
    import org.ehcache.config.builders.CacheManagerBuilder;
    import org.ehcache.config.builders.ResourcePoolsBuilder;
    
    public class EhcacheUtils {
        public static CacheManager cacheManager;
        
        public static void openCache(){
            cacheManager = CacheManagerBuilder.newCacheManagerBuilder()
                      .withCache("preConfigured",
                           CacheConfigurationBuilder.newCacheConfigurationBuilder(String.class, Object.class,
                                                          ResourcePoolsBuilder.heap(100))
                           .build())
                      .build(true);
        }
        
        public static void closeCache(){
            cacheManager.close();
        }
    }

    启动并添加一个缓存:

    EhcacheUtils.openCache();
            Cache<String, Object> myCache = EhcacheUtils.cacheManager.createCache("myCache", CacheConfigurationBuilder
                    .newCacheConfigurationBuilder(String.class, Object.class, ResourcePoolsBuilder.heap(100)).build());

    更新缓存:

    Map<String, String> sqls = null;
            if(myCache.containsKey("sqls")){
                sqls = (Map<String, String>)myCache.get("sqls");
            }else{
                sqls = new HashMap<String, String>();
            }
            
            sqls.put(fn.replaceAll(".sql", ""), sql);
            myCache.put("sqls", sqls);

    读取缓存:

    Cache<String, Object> myCache
                = EhcacheUtils.cacheManager.getCache("myCache", String.class, Object.class);
            Map<String, String> sqls = (Map<String, String>)myCache.get("sqls");

  • 相关阅读:
    Python文件操作
    Python操作MySQL数据库
    Can't connect to MySQL server (10065)
    CentOS安装Navicat
    机器学习中Batch Size、Iteration和Epoch的概念
    Python禁用GC优化性能
    TensorFlow迭代速度变慢的问题
    Linear SVM和LR的区别和联系
    拉格朗日乘子法和KKT条件
    Python机器学习(1):KMeans聚类
  • 原文地址:https://www.cnblogs.com/wpcnblog/p/9242504.html
Copyright © 2011-2022 走看看