Cache Konfiguration "ehcache.xml"

Über die ehcache.xml werden spezifischere Einstellungen definiert und zugewiesen. Im einzelnen können nachfolgende Einstellungen getroffen werden:

  • Verfallszeiten von Einträgen im Cache
  • Größe des Caches
  • Definieren von Cache Strategien welche dann unterschiedlichen Entities zugewiesen werden können


<config xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
	xmlns='http://www.ehcache.org/v3'
	xmlns:jsr107='http://www.ehcache.org/v3/jsr107'
	xsi:schemaLocation="
        http://www.ehcache.org/v3 http://www.ehcache.org/schema/ehcache-core-3.5.xsd
        http://www.ehcache.org/v3/jsr107 http://www.ehcache.org/schema/ehcache-107-ext-3.5.xsd">

	<service>
		<jsr107:defaults enable-management="true"
			enable-statistics="true" default-template="defaultCacheTemplate" />
	</service>

	<cache-template name="defaultCacheTemplate">
		<expiry>
			<!-- time to idle, the maximum time for an entry to remain untouched Entries 
				to the Cache can be made to expire after a given time other options are: 
				* <ttl>, time to live; * <class>, for a custom Expiry implementation; or 
				* <none>, for no expiry -->
			<!-- <tti unit="minutes">10</tti> -->
			<!-- <tti unit="seconds">10</tti> -->
			<!-- <ttl unit="seconds">1200</ttl> -->
			<none />
		</expiry>
		<resources>
			<!-- Maximum entries in memory -->
			<heap unit="entries">100000</heap>
			<!-- Maximum size in memory -->
			<!-- <heap unit="MB">10000</heap> -->
		</resources>
	</cache-template>

	<cache alias="org.hibernate.cache.spi.QueryResultsRegion">
		<expiry>
			<!-- time to idle, the maximum time for an entry to remain untouched Entries 
				to the Cache can be made to expire after a given time other options are: 
				* <ttl>, time to live; * <class>, for a custom Expiry implementation; or 
				* <none>, for no expiry -->
			<!-- <tti unit="minutes">10</tti> -->
			<!-- <tti unit="seconds">10</tti> -->
			<!-- <ttl unit="seconds">1200</ttl> -->
			<none />
		</expiry>
		<resources>
			<!-- Maximum entries in memory -->
			<heap unit="entries">100000</heap>
			<!-- Maximum size in memory -->
			<!-- <heap unit="MB">10000</heap> -->
		</resources>
	</cache>

	<!-- Because of this line the TimestampsRegionCache inherits its preferences 
		from the defaultCacheTemplate. If it is necessary to define different preferences 
		remove this line and use it like the lines above -->
	<cache alias="org.hibernate.cache.spi.TimestampsRegion"
		uses-template="defaultCacheTemplate" />

	<cache alias="com.company.charttest.entities.Employee"
		uses-template="defaultCacheTemplate" />
	<cache alias="com.company.charttest.entities.Order"
		uses-template="defaultCacheTemplate" />
	<cache alias="com.company.charttest.entities.Product"
		uses-template="defaultCacheTemplate" />
	<cache alias="com.company.charttest.entities.Customer"
		uses-template="defaultCacheTemplate" />
	<cache alias="com.company.charttest.entities.Category"
		uses-template="defaultCacheTemplate" />
	<cache alias="com.company.charttest.entities.Customerdemographic"
		uses-template="defaultCacheTemplate" />
	<cache alias="com.company.charttest.entities.Orderdetail"
		uses-template="defaultCacheTemplate" />
	<cache alias="com.company.charttest.entities.OrderdetailId"
		uses-template="defaultCacheTemplate" />
	<cache alias="com.company.charttest.entities.Region"
		uses-template="defaultCacheTemplate" />
	<cache alias="com.company.charttest.entities.Shipper"
		uses-template="defaultCacheTemplate" />
	<cache alias="com.company.charttest.entities.Supplier"
		uses-template="defaultCacheTemplate" />
	<cache alias="com.company.charttest.entities.Territory"
		uses-template="defaultCacheTemplate" />
</config>

Verfallszeiten definieren

<expiry>
	<!-- time to idle, the maximum time for an entry to remain untouched Entries to the Cache -->
	<tti unit="minutes">10</tti>
	<!-- oder -->
	<tti unit="seconds">10</tti>
</expiry>

Legt fest, nach welcher Zeit das Entity verworfen werden soll. Die Zeit beginnt nach jedem Zugriff immer wieder von neuem.

Time to live

<expiry>
	<!-- time to live, the maximum time for an entry to live in the Cache -->
	<ttl unit="minutes">10</ttl>
	<!-- oder -->
	<ttl unit="seconds">10</ttl>
</expiry>

Legt fest, nach welcher Zeit das Entity verworfen werden soll. Ungeachtet dessen, wie oft das Entity referenziert wurde.

Größe des Caches

<resources>
	<!-- Maximum entries -->
	<heap unit="entries">100000</heap>
	<!-- oder -->
	<!-- Maximum size in memory -->
	<!-- <heap unit="MB">10000</heap> -->
</resources>

Legt fest, wie groß der Cache maximal werden kann bis Elemente aus dem Cache geschoben werden

Definition von Cache Strategien und deren Zuweisungen

<cache-template name="defaultCacheTemplate">
		<expiry
			<tti unit="seconds">10</tti>
			<none />
		</expiry>
		<resources>
			<heap unit="MB">10000</heap>
		</resources>
</cache-template>


<cache-template name="advancedCacheTemplate">
		<expiry
			<tti unit="seconds">100</tti>
			<none />
		</expiry>
		<resources>
			<heap unit="MB">1000000</heap>
		</resources>
</cache-template>

<cache alias="com.company.charttest.entities.Supplier"
	uses-template="defaultCacheTemplate" />
<cache alias="com.company.charttest.entities.Territory"
	uses-template="advancedCacheTemplate" />

Legt für bestimmte Entities unterschiedliches Cache Verhalten fest.

XDEV Software Corp. - One Embarcadero Center, San Francisco, CA 94111, US
Copyright © 2015. XDEV Software Corp. All rights reserved.