cacheGetSession

Description

Lets you retrieve the underlying cache object to access additional cache functionality that is not implemented in the tag cfcache.

Returns

The underlying cache object.

Syntax

cacheGetSession()

Parameters

Parameter

Description

objectType

Any of the following values:

  • object

  • template

  • name of the user-defined cache

isKey

Set to true if objectType is user-defined cache. The default value is false.

History

ColdFusion 9.0.1: Added this function

Example 1

The following example shows how to create a user-defined cache by adding an entry in ehCache.xml:

<cache 
name="customcache" 
maxElementsInMemory="1000" 
eternal="false" 
timeToIdleSeconds="720" 
timeToLiveSeconds="720" 
overflowToDisk="true" 
diskSpoolBufferSizeMB="10" 
maxElementsOnDisk="100000" 
diskPersistent="true" 
diskExpiryThreadIntervalSeconds="3600" 
memoryStoreEvictionPolicy="LRU"/>

After you specify the details in the ehCache.xml, you can use the user-defined cache as shown here:

 <!--- put an object into user-defined object cache ---> 
      <cfset cachePut("cache1","hello",15,15,customCache)> 
      
      <!--- get underlying user-defined object cache ---> 
      <cfset objectCache = cachegetsession(customCache,true)> 
      
      <!--- get/print user-defined object cache properties ---> 
      <cfset config = objectCache.getCacheConfiguration()> 
      <cfoutput> 
            getMaxElementsInMemory() :: #config.getMaxElementsInMemory()#<br> 
            isEternal() ::    #config.isEternal()#<br> 
            getTimeToIdleSeconds() :: #config.getTimeToIdleSeconds()#<br> 
            getTimeToLiveSeconds() :: #config.getTimeToLiveSeconds()#<br> 
            isOverflowToDisk() :: #config.isOverflowToDisk()#<br> 
            getDiskSpoolBufferSizeMB() :: #config.getDiskSpoolBufferSizeMB()#<br> 
            getMaxElementsOnDisk() :: #config.getMaxElementsOnDisk()#<br> 
            isDiskPersistent() :: #config.isDiskPersistent()#<br> 
            getDiskExpiryThreadIntervalSeconds() :: #config.getDiskExpiryThreadIntervalSeconds()#<br> 
            getMemoryStoreEvictionPolicy() :: #config.getMemoryStoreEvictionPolicy()#<br> 
            isClearOnFlush() :: #config.isClearOnFlush()#<br> 
      </cfoutput>

Example 2

The following example shows how to use the function cacheGetSession to operate on default caches:

 <!--- put an object into user-defined object cache ---> 
      <cfset cachePut("cache1","hello",15,15)> 
      
      <!--- get underlying user-defined object cache ---> 
      <cfset objectCache = cachegetsession("object",true)> 
      
      <!--- get/print user-defined object cache properties ---> 
      <cfset config = objectCache.getCacheConfiguration()>