Originally posted by Sean Sullivan: I am looking for articles or books that describe if/how to apply the decorator pattern for the purposes of caching.
Decorator pattern for caching??? For all that i know decorator is a pattern that allows you to add a subclass that will have a functionality applicable to all other subclasses thereby reducing the number of classes in hierarchy. I wonder how it can be used for caching?Can you let know the reason for your choice?
Originally posted by Lasse Koskela: The idea was probably to "decorate" the existing class by introducing a cache check before calling the super class' getExpensiveInformation() method. For example:
hi lasse, Is this what you meant by decorating for cache???
If yes, we are not using decorator pattern for caching right??? If no, please clarify.
Joined: Jan 23, 2002
I should've named "MyCachedObject" as "MyDecoratedObject". That's what I meant. I realize some resources say that subclassing is not an implementation of the Decorator pattern. In that sense, composition would be a more appropriate way to implement the decorator. However, in order to do this transparently we'd need an interface to implement (or to use with a dynamic proxy).
I hadn't read that article. Now I have read the Caching section of it Yes, we need a standard caching method in J2EE. There is JSR-107, but it has been inactive for quite a while. Fortunately, there has been some changes in the expert group that could breathe new life into the JSR effort (Cameron Purdy of Tangosol was made the spec lead, Bela Ban from JavaGroups joined the expert group). There are already a couple of open-source cache implementations such as OSCache, Java Object Cache, and JCache.