User Guide Cancel

CacheIdExists

 

Description

Used to find if a cached object exists in the cache region. The region can be the default cache region (either at server or application level) or the custom region you specify.

Returns

True, if the cached object exists in the specified cache region.

History

ColdFusion 10: Added this function.

Syntax

cacheIdExists(id ,[region])
cacheIdExists(id ,[region])
cacheIdExists(id ,[region])

Properties

Parameter

Description

id

(Required) The ID of the cached object.

region

(Optional) The cache region where you check for the cached object.

Example: Checks if the cache object is present in the user-defined cache region

<cfscript>
// Create a new object
obj1 = {};
obj1.name = "hello world";
// Define the time to live and time to idle parameters
timeToLive=createtimespan(0,0,0,30);
timeToIdle=createtimespan(0,0,0,30);
writeOutput("Starting to write to cache..");
cachePut("id_obj1",obj1,timeToLive,timeToIdle,"customcache");
writeOutput("Done!!");
writeOutput("Trying to check if the cached item is present...");
writeOutput(cacheIdExists("obj1","customcache"));
</cfscript>
<cfscript> // Create a new object obj1 = {}; obj1.name = "hello world"; // Define the time to live and time to idle parameters timeToLive=createtimespan(0,0,0,30); timeToIdle=createtimespan(0,0,0,30); writeOutput("Starting to write to cache.."); cachePut("id_obj1",obj1,timeToLive,timeToIdle,"customcache"); writeOutput("Done!!"); writeOutput("Trying to check if the cached item is present..."); writeOutput(cacheIdExists("obj1","customcache")); </cfscript>
<cfscript>
       //  Create a new object 
       obj1 = {};
       obj1.name = "hello world";
       // Define the time to live and time to idle parameters 
       timeToLive=createtimespan(0,0,0,30);
       timeToIdle=createtimespan(0,0,0,30);
       writeOutput("Starting to write to cache..");
       cachePut("id_obj1",obj1,timeToLive,timeToIdle,"customcache");
       writeOutput("Done!!");
       writeOutput("Trying to check if the cached item is present...");
       writeOutput(cacheIdExists("obj1","customcache"));
</cfscript>

Get help faster and easier

New user?