Client side caching!
Hi,
We have a Java Web Start application, which caches around 500MB of heavy weight objects in memory. These corresponds to different reports and it kind of grows over the time. I am looking for some kind of architecture framework or some work around to maintain this cache at the client side. It is bit late to change the architecture and it is important to cache all the objects.
Could somebody suggest your views on this?
Thank You,
Vikram
Cross post:
http://forum.java.sun.com/thread.jspa?threadID=649133
http://forum.java.sun.com/thread.jspa?threadID=649132
http://forum.java.sun.com/thread.jspa?threadID=649134
http://forum.java.sun.com/thread.jspa?threadID=649136
http://forum.java.sun.com/thread.jspa?threadID=649137
http://forum.java.sun.com/thread.jspa?threadID=649138
Ignoring the blatant cross-posting, you could use AOP to implement an additive caching mechanism with potentially little or no impact on your existing code.
The basic idea is to identify the objects that you wish to cache along with the points in the client-side code that retrieve and update (for purposes of refreshing or invalidating the cache) cacheable objects. Apply around advice at the identifed points that first attempts to retrieve the object from the client-side cache before resorting to retrieving the object from the server, e.g. in AspectJ it'd be something like:
public aspect ReportCache {
private Cache cache = ... // Some cache implementation
/**
* Define the join point at which reports are retrieved by the client
* from the server
*/
public pointcut cacheableOperations(Serializable id) :
(call(public Report com.mypackage.ReportManager.getReportByName(String))
&& args(id)) || ...;
/**
* Check if the object has been cached before retrieving from the server.
*/
Object around(Serializable id) : cacheableOperations(id) {
Object obj = null;
if (cache.contains(id)) {
obj = cache.get(id);
} else {
obj = proceed(id); // not cached - get from server and cache
cache.put(id, obj);
}
return obj;
}
}
This strategy could be implemented using a hand-crafted cache, but I'm sure there are plenty of existing cache implementations that could be used (EHCache springs to mind).
roweja at 2007-7-11 16:18:00 >
