class="net.sf.ehcache.distribution.RMICacheReplicatorFactory"
properties="asynchronousReplicationIntervalMillis=200"/>
Ehcache
RecipesandCodeSamples
TheRecipesandCodeSamplespagecontainsrecipes-shortconciseexamplesforspecificusecases-andasetofcodesamplesthatwillhelpyougetstartedwithEhcache.
Ifyouhaveasuggestionoranideaforarecipeormorecodesamples,pleasetellusaboutitusingthemailinglistorforums.
Recipes
Recipe
Description
WebPageandFragmentCaching
HowtouseinludedServletFilterstoCacheWebPageandWebPageFragments
DataFreshnessandExpiration
Howtomaintaincache"freshness"byconfiguringTTLanddataexpirationproperly
EnableTerracottaProgrammatically
HowtoenableTerracottasupportforEhcacheprogrammatically
CachingEmptyValues
Whycachingemptyvaluescanbedesirabletodeflectloadfromthedatabase
DatabaseOverload
Whenmanyreaderssimultaneouslyrequestthesamedataelementitiscalledthe"ThunderingHerd"problem.Howtopreventitinasinglejvmorclusteredconfiguration
CachingmethodswithSpringAnnotations
AddingcachingtomethodsusingEhcacheAnnotationsforSpringproject
CacheWrapper
AsimpleclasstomakeaccessingEhcacheeasierforsimpleusecases
CodeSamples
∙UsingtheCacheManager
oSingletonversusInstance
oWaysofloadingCacheConfiguration
oAddingandRemovingCachesProgrammatically
oShutdowntheCacheManager
∙CreatingCachesProgrammatically
oCreatinganewcachefromdefaults
oCreatinganewcachewithcustomparameters
∙UsingCaches
oObtainingareferencetoaCache
oPerformingCRUDoperations
oDiskPersistenceondemand
oObtainingCacheSizes
oObtainingStatisticsofCacheHitsandMisses
oDynamicallyModifyingCacheConfigurations
oJTA
∙UsingDistributedCaches
oTerracottaExample
∙CacheStatisticsandMonitoring
oRegisteringCacheStatisticsinanMBeanServer
∙Moreexamples
oJCacheExamples
oCacheServerExamples
oBrowsetheJUnitTests
UsingtheCacheManager
AllusagesofEhcachestartwiththecreationofaCacheManager.
SingletonversusInstance
Asofehcache-1.2,EhcacheCacheManagerscanbecreatedaseithersingletons(usethecreatefactorymethod)orinstances(usenew).
CreateasingletonCacheManagerusingdefaults,thenlistcaches.
CacheManager.create();
String[]cacheNames=CacheManager.getInstance().getCacheNames();
CreateaCacheManagerinstanceusingdefaults,thenlistcaches.
CacheManagermanager=newCacheManager();
String[]cacheNames=manager.getCacheNames();
CreatetwoCacheManagers,eachwithadifferentconfiguration,andlistthecachesineach.
CacheManagermanager1=newCacheManager("src/config/ehcache1.xml");
CacheManagermanager2=newCacheManager("src/config/ehcache2.xml");
String[]cacheNamesForManager1=manager1.getCacheNames();
String[]cacheNamesFo