Skip to content

How to take a quick peak into your Coldfusion ORM EhCache

August 20, 2010

The other day I was trying to performance tune one of my new applications  which is based on Coldfusion and uses ORM for all the db interactions.   I wanted to make sure the cache was setup and was being used.  I also wanted to know how many cache hits and misses there were and the size of the cache region.  I looked around and based on some other blog post and help wikis I came up with the following handy little script that I thought others might like to use.

<h2>Cache Info</h2>

<cfscript>
stats = ormGetSessionFactory().getStatistics();
//turn on stats if they are not enabled, they are not enabled by default
if(!stats.isStatisticsEnabled()){
     stats.setStatisticsEnabled(true);
}

if(stats.isStatisticsEnabled()){
//Get the cache region names array
cacheRegionNames = stats.getSecondLevelCacheRegionNames();

for(i=1;i LTE arraylen(cacheRegionNames);i++){
     writeoutput("Cache Stats for region " & cacheRegionNames[i]);
     writeoutput("<br/>getElementCountInMemory " & stats.getSecondLevelCacheStatistics(cacheRegionNames[i]).getElementCountInMemory());
     writeoutput("<br/>getElementCountOnDisk " & stats.getSecondLevelCacheStatistics(cacheRegionNames[i]).getElementCountOnDisk());
     writeoutput("<br/>getHitCount " & stats.getSecondLevelCacheStatistics(cacheRegionNames[i]).getHitCount());
     writeoutput("<br/>getMissCount " & stats.getSecondLevelCacheStatistics(cacheRegionNames[i]).getMissCount());
     writeoutput("<br/>getSizeInMemory " & (stats.getSecondLevelCacheStatistics(cacheRegionNames[i]).getSizeInMemory() / 1024) & " kb");
     writeoutput("<br/>");
     writeoutput("<br/>");
}
</cfscript>

Advertisement

From → Coding

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.