1. 程式人生 > >ehchche配置中配置多個快取物件

ehchche配置中配置多個快取物件

Ehcache不允許建立同樣名稱的CacheManager物件。如果我們沒有ehcache.xml中配置CacaheManager的名稱,那麼預設的名稱是__DEFAULT__。解決方式是<ehcache name="">中配置CacheManager的名稱,並確保唯一。這樣如下程式碼就不會報錯了
  1. URL url = CacheHelper.class.getClassLoader().getResource("ehcache.xml");  
  2. CacheManager manager = new CacheManager(url);  
  3.  // __DEFAULT__
  4. System.out.println(manager.getName());  
  5. URL url2 = CacheHelper.class.getClassLoader().getResource("ehcache2.xml");  
  6. CacheManager manager2 = new CacheManager(url2); 
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////ehcache.xml
<?xml version="1.0" encoding="UTF-8"?>
<ehcache>

<!--<diskStore path="/home/uat_dm/log/ehcache/oss"/>-->
<diskStore path="java.io.tmpdir/hibernate/oss" />
<defaultCache maxElementsInMemory="10000" memoryStoreEvictionPolicy="LRU" eternal="false"
timeToIdleSeconds="300" timeToLiveSeconds="300" overflowToDisk="false" diskPersistent="false" />

<!-- acegi cache-->
<cache name="userCache"
maxElementsInMemory="10000"
eternal="true"
overflowToDisk="true"/>

<!-- acegi cache-->
<cache name="resourceCache"
maxElementsInMemory="10000"
eternal="true"
overflowToDisk="true"/>
<cache name="paramCache"
maxElementsInMemory="10000"
eternal="true"
overflowToDisk="true"/>

</ehcache>

建立這些快取物件,如何使用嫩

//建立CacheManager物件

  CacheManager manager = CacheManager.getInstance();
            if(manager == null)
                manager = CacheManager.create();
           //通過Cachemanager物件
            cache = manager.getCache("paramCache");
            
            if(cache == null){
                log.error("init cache failed");
                manager.addCache("paramCache");
//獲取ehcache.xmL配置檔案裡的cache物件
                cache = manager.getCache("paramCache");
                
            }
            for(TC09ParamDic c09 : c09List){
                ParamCacheKey key = new ParamCacheKey(c09.getParamName(), c09.getValue());
                cache.put(new Element(key, c09));
            }

相關推薦

ehchche配置配置快取物件

Ehcache不允許建立同樣名稱的CacheManager物件。如果我們沒有ehcache.xml中配置CacaheManager的名稱,那麼預設的名稱是__DEFAULT__。解決方式是<ehcache name="">中配置CacheManager的名稱,並

git配置出現重復名字:More than one value for the key user.name

for val config repl -s user nvic -c 區域 #### 查看配置```git config --list``` #### 查看所有的名稱```git config --get-all user.name``` #### 查

SpringBoot配置檔案的屬性進行提取的簡易方法

我們要提取一下屬性: 首先建立一個GirlProperties類 package com.springboot.properties; import org.springframework.boot.context.properties.ConfigurationPropertie

Spring配置和讀取Properties檔案--轉

    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">       &

Jenkins pipeline下載配置

場景:        流水構建場景有時候需要下載多個配置庫的程式碼        參考https://stackoverflow.com/questions/40224272/using-a-jenkins-pipeline-to-checkout-multiple-g

如何在spring配置集合供Bean使用

一:Utility   Scheme 1.使用基本的集合標籤定義集合時,不能將集合作為獨立的Bean定義,導致其他Bean無法引用該集合,所以無法在不同Bean之間 共享集合。 2.可以使用Utility  Scheme裡的集合標籤定義獨立的集合Bean,需要的是在B

classpath:和classpath*:的區別以及web.xml載入配置檔案

首先我們都知道要使用spring,則需要在web.xml中增加如下程式碼:  Xml程式碼      <listener>  <listener-class> org.springfram

五、Django專案包含應用時對url的配置

一個Django工程中多數情況下會存在多個應用, 如何針對多個應用的url進行配置呢,有以下兩種方案: 1、在Django工程的urls.py中針對每個應用分別配置不同的url路徑 2、在工程總體的urls.py中引入每個應用的url配置檔案,不

Struts2之動態方法呼叫(優點:呼叫同一個action方法不需要在配置檔案指向相同action類的的action節點只需要一個action節點就行)

在表單action值裡指定所呼叫的action中的哪個方法而不是藉助配置檔案action節點的method屬性 1 UserAction類 package org.action; import java.io.IOException; import javax.servle

怎麼在web.xml配置一個對應

   <filter>   <filter-name>loginFilter2</filter-name>   <filter-class>de.base.LoginFilter</filter-class>  

電腦安裝Tomcat,如何配置(已經解決)

     當電腦中已經有一個Tomcat時,由於不同的專案需要,所支援的Tomcat的版本不同,因此一個電腦中需要安裝多個Tomcat,接下來介紹怎樣安裝多個Tomcat的具體實現:      安裝前

AndroidStudio配置settings.gradle在工程構建專案

諮詢,合作郵箱: [email protected] GitHub: https://github.com/DeMonLiu623 由於之前整理GitHub,刪除了一些專案,所以導致部分程式碼連結失效。如有需要,請留言,或者私信! 另外:由於CSDN的下載積分會

Struts使用配置檔案 struts-config.xml

或許很多開發人員都面臨著這樣的困惑,那就是struct-config.xml檔案中有很多的配置,什麼action,formbean..... 我這裡說的100個action那是很小的專案了,呵呵,看得眼花繚亂,不利於模組化的開發和維護;解決的方法就是把struct-conf

log4j配置輸出到日誌文件

基準 方式 ref err logfile otl sni targe file 通常我們項目裏,有一些重要的日誌想單獨的輸出到指定的文件,而不是全總輸出到系統的日誌文件中。那麽我們log4j為我們提供了這種功能,以下我們來一步一步看是怎麽做的。這裏以pro

spring配置加載properties文件

lac 存在 cnblogs org bsp 讀取 ace val cati (一)首先,我們要先在spring配置文件中。定義一個專門讀取properties文件的類.例: 1 <bean id="propertyConfigurer" class="org.sp

log4j配置輸出到日誌文件(轉)

兩種模式 簡單 mylog 效果 evel ast mar 輸出 rop 參考資料:http://logging.apache.org/log4j/1.2/manual.html 通常我們項目裏,有一些重要的日誌想單獨的輸出到指定的文件,而不是全總輸出到系統的日誌文件中。那

Ubuntu16.04配置Apache支援站點

怎樣在一個Ubuntu的機器上(虛擬機器)配置Apache支援多個網站呢? 比如你有一臺獨立的Ubuntu虛擬機器,配有一個外網的IP(45.46.47.48),並且註冊了兩個域名AAA.com和BBB.com,將這兩個域名DNS解析到你虛機的IP地址。假設你已經安裝好了Apache,一

springboot不同物件的屬性進行比較,將不同的值用使用陣列查詢出,並儲存在意向表

多表維護 @MethodParameter(desc="orgTenantTypeQueryAll",input="user",postType={},postName="",queryString="",httpMethod="get",userParam="user

一個表單相同的欄位,以及springmvc接收相同物件問題

                                      &

nginx 配置一個或者域名

 nginx 配置一個或者多個域名 cd etc/nginx/ 進入到nginx目錄 vi nginx.conf  server 一個為例 server { listen 80 default_server