File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Decorator pattern, caching

 
Sean Sullivan
Ranch Hand
Posts: 427
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am looking for articles or books that describe if/how to apply
the decorator pattern for the purposes of caching.
 
william kane
Ranch Hand
Posts: 260
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The idea was probably to "decorate" the existing class by introducing a cache check before calling the super class' getExpensiveInformation() method.
For example:
 
william kane
Ranch Hand
Posts: 260
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
Pradeep bhatt
Ranch Hand
Posts: 8927
Firefox Browser Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
http://www.onjava.com/lpt/a/4361
The example shows how caching can be acheived using Filters.
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Pradeep Bhat:
http://www.onjava.com/lpt/a/4361
The example shows how caching can be acheived using Filters.

That's a great article, Pradeep, but not really helping in implementing an object-level cache.
 
Pradeep bhatt
Ranch Hand
Posts: 8927
Firefox Browser Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Lasse Koskela:

That's a great article, Pradeep, but not really helping in implementing an object-level cache.


Lasse,
Have you read the Caching section of the article
http://msdn.microsoft.com/asp.net/default.aspx?pull=/library/en-us/dnaspp/html/aspnet-aspnet-j2ee-struts.asp
ASP .NET provides object-level caching. I feel that J2EE also needs to come up with some caching standard. What is you opinion Lasse?
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic