Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

CF Dude, What's in the cache?

DZone's Guide to

CF Dude, What's in the cache?

· Java Zone
Free Resource

Microservices! They are everywhere, or at least, the term is. When should you use a microservice architecture? What factors should be considered when making that decision? Do the benefits outweigh the costs? Why is everyone so excited about them, anyway?  Brought to you in partnership with IBM.

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.
<cfscript>
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":
        cacheRemove(url.item);
        writeOutput("<div style='color: green; font-weight: bold'>Removed #url.item#</div>");
    break;
    case "view":
        writeDump( var=cacheGet(url.item), label="Cache contents of: " & url.item, top=10 );
    break;
    case "meta":
        writeDump( var=cacheGetMetadata(url.item), label="Metadata for: " & url.item );
    break;
}

incache = cacheGetAllIds();
arraySort(incache,"textnocase");
</cfscript>

<cfoutput>
<h3>Cache IDs</h3>

    <table cellspacing="4">
    <cfloop array="#incache#" index="c">
        <tr>
            <td>#c#</td>
            <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>
        </tr>

    </cfloop>
    </table>

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


Discover how the Watson team is further developing SDKs in Java, Node.js, Python, iOS, and Android to access these services and make programming easy. Brought to you in partnership with IBM.

Topics:

Published at DZone with permission of Sam Farmer, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

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

{{ parent.tldr }}

{{ parent.urlSource.name }}