Cache opinion

Posts   
 
    
mikeg22
User
Posts: 411
Joined: 30-Jun-2005
# Posted on: 29-Aug-2006 23:37:04   

I am building a cache between our Data Access Layer and business layer to cache security information for specific users. I have the option of building a self updating mechanism into my cache class (whic is derived from DictionaryBase). So, for example, if myCache(userName) doesn't exist already, the fetch logic would be placed inside the Item property of the cache so the data would be fetched right then and there.

Anyone have any thoughts on this? I know that traditional cache classes use cache managers to supply them with data, but I can't think of a reason not to do it the way I mentioned in the above paragraph...for one thing it helps with being able to localize the SyncLocks in the cache itself.

Walaa avatar
Walaa
Support Team
Posts: 14983
Joined: 21-Aug-2005
# Posted on: 30-Aug-2006 07:36:01   

I can see nothing against your way. People tend to use manager classes for the sake of abstraction and responsibility distribution between classes. In another words, this is only a way to organize code.

omar avatar
omar
User
Posts: 569
Joined: 15-Oct-2004
# Posted on: 04-Sep-2006 08:23:25   

Why dont u store a user's security data in a context like object that gets created for every user when he loggs in. This singleton context object can live for the duration of the user's session.

mikeg22
User
Posts: 411
Joined: 30-Jun-2005
# Posted on: 05-Sep-2006 21:37:23   

omar wrote:

Why dont u store a user's security data in a context like object that gets created for every user when he loggs in. This singleton context object can live for the duration of the user's session.

I guess thats kind of what my cache object is. Our system has all kinds of security data possible for a user, so I wanted to lazy load the cache with security data (as opposed to getting it all in one shot). I was just wondering if I was doing something theoretically wrong by giving the cache object the ability to fill itself up with data when that data was requested, and not yet in the cache.

In the end, I ended up making a dumb cache, where it can only store data, not get it. There is a singleton security object that uses this cache which gets data from the database if it isn't yet in the cache. The main reason to use a dumb cache like this was that the fact that some data was requested from the security system shouldn't automatically imply that that information should be cached, so the layer above the cache should have the freedom to get data without it getting cached...it can obviously also cache the data if it wants to.