Ehcache 1.5.0 User Guide - Cache Configuration 緩存配置(1)

  Ehcache 1.5.0 User Guide - Cache Configuration 緩存配置(1)

Ehcache 1.5.0 用戶指南)

E_mail:[email protected]

Blog: http://blog.csdn.net/jianglike18

qq:29396597

6Cache Configuration (緩存配置)

Caches can be configured in ehcache either declaratively, in xml, or by creating them programmatically and specifying their parameters in the constructor.

While both approaches are fully supported it is generally a good idea to separate the cache configuration from runtime use. There are also these benefits:

  • It is easy if you have all of your configuration in one place. Caches consume memory, and disk space. They need to be carefully tuned. You can see the total effect in a configuration file. You could do this code, but it would not as visible.
  • Cache configuration can be changed at deployment time.
  • Configuration errors can be checked for at start-up, rather than causing a runtime error.

(在ehcache中,緩存可以在xml中配置,或者由程序創建並在構造函數中設置他們的參數

雖然兩種方法都完全支持,但是將緩存的配置和運行時使用分開一般比較好,有如下好處:

l        如果讓你所有的配置在一個地方比較方便。緩存消耗內存和磁盤空間。他們需要仔細調整。在配置文件中你可以看到的總體影響。用代碼你可以做到這一點,但它不會成爲可見。

l        緩存的配置可以在部署的時候更改。

l        配置的錯誤在啓動時候可以被檢查出來,比在導致運行時候錯誤要好。

This chapter covers XML declarative configuration. See the Code samples for programmatic configuration.

Ehcache is redistributed by lots of projects. They may or may not provide a sample ehcache XML configuration file. If one is not provided, download ehcache from http://ehcache.sf.net . It, and the ehcache.xsd is provided in the distribution.

(本章節涉及xml申明的配置,看代碼實例瞭解程序配置。

Ehcache被許多項目重新分配,他們可能或沒有提供簡單的ehcachexml配置例子。如果沒有,可以從http://ehcache.sf.net下載ehcache。發行的版本中會提供ehcacheehcache.xsd。)

 

ehcache.xsd

Ehcache configuration files must be comply with the ehcache XML schema, ehcache.xsd, reproduced below.

It can also be downloaded from http://ehcache.sf.net/ehcache.xsd .

ehcache.xsd

  Ehcache配置文件,必須符合ehcache XML結構,即ehcache.xsd,如下複製ehcache.xsd的內容。

從網址http://ehcache.sf.net/ehcache.xsd也可以下載ehcache.xsd

 

ehcache-failsafe.xml

If the CacheManager default constructor or factory method is called, ehcache looks for a file called ehcache.xml in the top level of the classpath. Failing that it looks for ehcache-failsafe.xml in the classpath. ehcache-failsafe.xml is packaged in the ehcache jar and should always be found.

ehcache-failsafe.xml provides an extremely simple default configuration to enable users to get started before they create their own ehcache.xml.

ehcache-failsafe.xml

  如果CacheManager默認構造方法或工廠方法被調用,ehcache會在頂層的類路徑中查找ehcache.xml文件。如果沒有找到,那麼ehcache就會在類路徑中查找ehcache-failsafe.xml文件。ehcache-failsafe.xml被放在ehcachejar包中,應該總是可以找到。在用戶創建他們自定義的ehcache.xml ,ehcache-failsafe.xml提供了一個非常簡單的默認配置讓用戶可以開始.

 

If it used ehcache will emit a warning, reminding the user to set up a proper configuration.

The meaning of the elments and attributes are explained in the section on ehcache.xml.

(如果使用了ehcache-failsafe.xmd, ehcache會發出一個警告,提醒用戶設置一個適當的配置。

成員和屬性的含義在文件ehcache.xml中有解釋)

 

<ehcache>

    <diskStore path="java.io.tmpdir"/>

    <defaultCache

            maxElementsInMemory="10000"

            eternal="false"

            timeToIdleSeconds="120"

            timeToLiveSeconds="120"

            overflowToDisk="true"

            maxElementsOnDisk="10000000"

            diskPersistent="false"

            diskExpiryThreadIntervalSeconds="120"

            memoryStoreEvictionPolicy="LRU"

            />

</ehcache>

 

ehcache.xml and other configuration filesehcache.xml和其他的配置文件)

 

Prior to ehcache-1.6, ehcache only supported ASCII ehcache.xml configuration files. Since ehcache-1.6, UTF8 is supported, so that configuration can use Unicode. As UTF8 is backwardly compatible with ASCII, no conversion is necessary.

(ehcache 1.6以前的版本配置文件只支持ASCII格式.1.6版開始配置文件支持UTF8格式,因此配置可使用Unicode編碼.UTF8格式向後兼容ASCII格式,所以不需要進行轉換.)

 

If the CacheManager default constructor or factory method is called, ehcache looks for a file called ehcache.xml in the top level of the classpath.

The non-default creation methods allow a configuration file to be specified which can be called anything.

(如果CacheManager默認構造方法或工廠方法被調用,ehcache會在頂層的類路徑中查找ehcache.xml文件。

非默認的構造方法允許指定特別的配置文件,且配置文件名可以任意命名。)

 

One XML configuration is required for each CacheManager that is created. It is an error to use the same configuration, because things like directory paths and listener ports will conflict. Ehcache will attempt to resolve conflicts and will emit a warning reminding the user to configure a separate configuration for multiple CacheManagers with conflicting settings.

The sample ehcache.xml, which is included in the ehcache distribution is reproduced below. The sample contains full commentary required to configure each element. Further information can be found in specific chapters in the Guide.

It can also be downloaded from http://ehcache.sf.net/ehcache.xml .

(每一個CacheManager類被創建時,一個XML配置文件是必須的。用相同的配置是錯誤的,因爲像目錄路徑和監聽的端口會有衝突。Ehcache會嘗試解決衝突和發出警告提醒用戶爲有衝突的CacheManager對象配置單獨配置信息。

在發佈ehcache版本的包裏面包含了一個ehcache.xml配置文件的例子,ehcache.xml文件的內容被複制在下面了。該例子包含需要配置每個元素的完整註解。更多的信息可以在指導手冊具體章節中找到。

ehcache.xml文件也可以從http://ehcache.sf.net/ehcache.xml下載。)

 

發佈了54 篇原創文章 · 獲贊 6 · 訪問量 17萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章