calum.org:~#

Database caching in Java

Tags: programming, java,

Added: 2010-10-01T21:43:38

Database caching in Java

I decided to throw some caching at this site, and settled on Ehcache. I downloaded the annotations too, and sprinkled a few @Cacheables around my code.

Hey presto, instant win. You can see when I implemented it by checking out this graph of the page load times of the front page (or this one, since the move to a new VPS).

I just need to tweak it a little, and make sure that the caching doesn't last too long, and we'll be good.
If you're curious, the remaining time loading the page is caused by waiting for the page load time to be logged, bizarrely. A little write-behind will solve that. Perfect.

Update: The only weird thing is, is that the Statistics of the cache don't show any cache hits - or misses.

CacheManager cacheManager  = (CacheManager) WebApplicationContextUtils.getWebApplicationContext(getServletContext()).getBean("ehCacheManager");
Cache tmpcache = cacheManager.getCache("cachename");
Statistics tmpstats = tmpcache.getStatistics();
out.println(tmpstats.getInMemoryHits()); // Shows 0 all the time - any ideas?

The object count does go up though, so it's definitely hooked in to the right thing.

Update 2: I had to add statistics="true" to every cache defined in ehcache.xml.

posted by Calum on 2010-10-01T21:47 under

Comments

Comment

Thanks !
Add a comment

Your IP:
Please enter 8670181 here: