User Guide Cancel

CacheGetSession

 

Description

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

Note: CautionUsing the cacheGetSession function might pose security vulnerabilities. If you wish to disable the usage of this function, add it to Sandbox Security. For more information, see Using sandbox security.

Returns

The underlying cache object.

Syntax

cacheGetSession(objectType,[isKey])
cacheGetSession(objectType,[isKey])
cacheGetSession(objectType,[isKey])

Parameters

Parameter

Description

objectType

Any of the following values:

  • object
  • template
  • name of the user-defined cache

isKey

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

Category

Cache functions

See also

cfcache CachePutCacheGetCacheGetAllIdsCacheGetMetadataCacheRemoveCacheSetProperties

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"/>
<cache name="customcache" maxElementsInMemory="1000" eternal="false" timeToIdleSeconds="720" timeToLiveSeconds="720" overflowToDisk="true" diskSpoolBufferSizeMB="10" maxElementsOnDisk="100000" diskPersistent="true" diskExpiryThreadIntervalSeconds="3600" memoryStoreEvictionPolicy="LRU"/>
<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>
<!--- 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>
<!--- 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()>
<!--- 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()>
<!--- 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()>

Get help faster and easier

New user?