Hi Joe,
 
We're on parallel track somehow (for a cache mechanism, not a design pattern), although my implementation is very simplistic.
I have to confess that I can't really get into your logic, don't know what the GenericCacheFactory does,
but it seems very impressive from my newbie point of view :o)
 
Are you using the application, server or session scopes? How do you implement it ?
I created a simple XML schema, that represents a config class, when system starts I load it and use the values (applicationName, timeout etc)
in an application tag that I store under the constructor of my cache mechanism.
 
Why would you want to have a sizedCachedCollection separated from the timedCachedCollection ?
I understand the need to separate at maximum each class, but can't you have the size stored under some cache property on the genericCachedCollection.
A cacheCollection should know it's size and should count the elements it holds, shouldn't it ?
 
Regards,
 
Marcantonio Silva
Diretor de Desenvolvimento de Produtos - Navita
[EMAIL PROTECTED]
www.navita.com.br
Tel: +55 11 3055.2004
Cel: +55 11 7732.4907 (novo)

 

----- Original Message -----
Sent: Monday, January 10, 2005 1:26 PM
Subject: [CFCDev] Cache design using decorators and factories - advice/criticism?

Hey folks,

I need a super-generic container in which to keep stuff, i.e., a
cache.  I need to be able to have the cache manage its items either
based on cache size (can't grow above N items), or time (if I ask for
an item that's past it's expiration, a specialized error is thrown).

My first attempt at this taught me some of the evils of
over-inheritance - I had a GenericCache that just held stuff, with two
subclasses - TimedCache and SizedCache.  As the complication level of
some things grew, they got pretty unruly:  sized cache needed things
in the base that timed didn't, timed needed things in the base sized
didn't, and things got tangled.

Now, I've tried to break this apart into a cleaner system using
decorators and factories.  My design consists of the following CFCs:

GenericCacheItem - An item in the cache
GenericCache - decorated by a GenericCacheCollection (or subclass)
GenericCacheCollection - decorated by a GenericCacheCollectionManager
(or subclass)
GenericCacheCollectionManager - single method, cacheContains(key). 
When GenericCacheCollection.get(key) is called, it first calls
cacheContains(key), which  determines whether or not the item is still
valid, and if not, removes it from the cache

I've built a GenericCacheFactory that builds a GenericCacheCollection,
decorates it GenericCacheCollectionManager, builds a cache, and
decorates it with the GenericCacheCollection that's just been built.

To enable a sized cache, I subclass GenericCacheCollection with
SizedCacheCollection, which adds logic to the put() method that'll
remove the oldest item from the cache if the cache is above a maximum
size (set in SizedCacheCollection's init() method).  I then built a
SizedCacheFactory that builds a SizedCacheCollection, decorates it
with a GenericCacheCollectionManager, builds a cache, and decorates it
with the SizedCacheCollection I've just build.

To enable a time-based cache, I subclass GenericCacheCollectionManager
with TimedCacheCollectionManager that's told about a cache item's
lifespan in its init() method.  The factory then assembles these like
the GenericCacheFactory, decorating the collection with the TimedCache
manager instead of the GenericCache manager.

Does anyone have any advice/critique/etc. on doing things like this?
Is this a "proper" implementation of using the decorator pattern?

The end result, regardless, is pretty cool...I just create the
concrete factory for the type of cache I need, call its createCache
method, and it gives me the correct, decorated GenericCache.

-Joe




--
For Tabs, Trees, and more, use the jComponents:
http://clearsoftware.net/client/jComponents.cfm
----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email
to [EMAIL PROTECTED] with the words 'unsubscribe cfcdev'
in the message of the email.

CFCDev is run by CFCZone (www.cfczone.org) and supported
by Mindtool, Corporation (www.mindtool.com).

An archive of the CFCDev list is available at www.mail-archive.com/[email protected]

Reply via email to