Over a million developers have joined DZone.

CF Dude, What's in the cache?

DZone's Guide to

CF Dude, What's in the cache?

· Java Zone ·
Free Resource

Get the Edge with a Professional Java IDE. 30-day free trial.

Over the weekend I needed to see what was in my cache. I whipped up a quick script to list everything in cache and from there:

  • be able to remove an item
  • view the content of an item (limited to top 10 records)
  • view the metadata of an item.
I've included the code below.
writeOutput('<h2>CF Dude, What''s in the cache?</h2><div><a href="#cgi.script_name#">Reload</a><br><br></div>');

param name="url.do" default="";

switch (url.do) {
    case "remove":
        writeOutput("<div style='color: green; font-weight: bold'>Removed #url.item#</div>");
    case "view":
        writeDump( var=cacheGet(url.item), label="Cache contents of: " & url.item, top=10 );
    case "meta":
        writeDump( var=cacheGetMetadata(url.item), label="Metadata for: " & url.item );

incache = cacheGetAllIds();

<h3>Cache IDs</h3>

    <table cellspacing="4">
    <cfloop array="#incache#" index="c">
            <td><a href="#cgi.script_name#?do=remove&item=#c#">remove</a></td>
            <td><a href="#cgi.script_name#?do=view&item=#c#">view</a></td>
            <td><a href="#cgi.script_name#?do=meta&item=#c#">meta</a></td>


<h3>Cache Properties</h3>
<cfdump var="#cacheGetProperties()#">

Get the Java IDE that understands code & makes developing enjoyable. Level up your code with IntelliJ IDEA. Download the free trial.


Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}