How to take a quick peak into your Coldfusion ORM EhCache
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
Leave a Comment