HighTechTalks DotNet Forums  

Advice on cache design

ASP.net Caching microsoft.public.dotnet.framework.aspnet.caching


Discuss Advice on cache design in the ASP.net Caching forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Stephen Woolhead
 
Posts: n/a

Default Advice on cache design - 10-22-2004 , 09:07 PM






Hi all, I am looking for some advice on how to implement a caching solution
for use in my asp.net app.

I have a function that returns a simple true or false, but to get the answer
needs to execute appox 20 queries to the database. This function gets
called a lot so I want to store the result in a cache. The problem is that
the function is dependent on three parameters two of which are indexes of
lists stored in the database, a change to any of these lists invalidates the
function's cached results.

What I need to implement is a cache where I can invalidate all cache items
that have a dependency on a certain list index.

At the moment, I have a database table which looks like this

MembershipListID, AccessListID, OperationID, result, timestamp

Everytime this function is called, I check to see if there is a result in
the cache table, if the is I use it otherwise I do the work and an entry to
the cache table.

If the value of one of the lists changes I issue a delete for all records
that use that list ID.

Now I would like to move this to the ASP.NET cache for a bit more speed, and
ease of management but am not sure how to.

My best idea at the moment is to create dummy cache entries for each of the
list indexes and then create a cache dependency on these keys for each
result that goes into the cache, something like this.

MembershipListID = 4
AccessListID = 8
OperationID = 3
Result = true

So I would add the following place holders for creating cache dependencies

MLID#4
ALID#8

I would then add another cache item with the key FR#4#8#3 with the value
true and cache dependencies on MLID#4 and ALID#8

When one of the lists changes, I would remove the place holder key from the
cache, for example MLID#4 and that would remove all the function results
dependant on it.

Is this the best way to solve something like this?

Also while I have your attention, what is the accepted way to namespace your
cache entries? I don't want my cache entries to get confused with another
assemleblies data, so what do I do? Pre/post fix the key with the assembly
name or public key?

Thanks

Stephen



Reply With Quote
  #2  
Old   
Alvin Bruney [MVP]
 
Posts: n/a

Default Re: Advice on cache design - 10-23-2004 , 01:34 PM






..net version prior to 2.0 do not support cache dependencies at the database
level so you can either use your approache which seems sound to me, or you
can set a global flag to dirty everytime the lists changes. Test this flag
before retrieving cached results. if it is dirty, grab from the database and
update the flag to clean. Just depends on which way you want to go
architecture wise.


Quote:
Also while I have your attention, what is the accepted way to namespace
your cache entries?
have a look at MSDN for naming conventions. I do not particularly adhere to
them so i'm not in a position to dispense advice.

--
Regards,
Alvin Bruney
[ASP.NET MVP http://mvp.support.microsoft.com/default.aspx]
Got tidbits? Get it here... http://tinyurl.com/27cok
"Stephen Woolhead" <stephen (AT) perfectphase (DOT) com> wrote

Quote:
Hi all, I am looking for some advice on how to implement a caching
solution for use in my asp.net app.

I have a function that returns a simple true or false, but to get the
answer needs to execute appox 20 queries to the database. This function
gets called a lot so I want to store the result in a cache. The problem
is that the function is dependent on three parameters two of which are
indexes of lists stored in the database, a change to any of these lists
invalidates the function's cached results.

What I need to implement is a cache where I can invalidate all cache items
that have a dependency on a certain list index.

At the moment, I have a database table which looks like this

MembershipListID, AccessListID, OperationID, result, timestamp

Everytime this function is called, I check to see if there is a result in
the cache table, if the is I use it otherwise I do the work and an entry
to the cache table.

If the value of one of the lists changes I issue a delete for all records
that use that list ID.

Now I would like to move this to the ASP.NET cache for a bit more speed,
and ease of management but am not sure how to.

My best idea at the moment is to create dummy cache entries for each of
the list indexes and then create a cache dependency on these keys for each
result that goes into the cache, something like this.

MembershipListID = 4
AccessListID = 8
OperationID = 3
Result = true

So I would add the following place holders for creating cache dependencies

MLID#4
ALID#8

I would then add another cache item with the key FR#4#8#3 with the value
true and cache dependencies on MLID#4 and ALID#8

When one of the lists changes, I would remove the place holder key from
the cache, for example MLID#4 and that would remove all the function
results dependant on it.

Is this the best way to solve something like this?

Also while I have your attention, what is the accepted way to namespace
your cache entries? I don't want my cache entries to get confused with
another assemleblies data, so what do I do? Pre/post fix the key with the
assembly name or public key?

Thanks

Stephen





Reply With Quote
  #3  
Old   
Donald Babcock
 
Posts: n/a

Default Re: Advice on cache design - 11-06-2004 , 11:40 PM





this solution works pretty well, it doable with application level caches
as well...

It works fine until you want to have the page which updates the DB do a
post back, and have the updated Cached data play a roll in the postback
. The nature of ASP.NET processes the postback first, and then applys
the event triggers. One solution is to have events call page_load, but
that is far from efficient.

I have seen a DB flagger writtern for VB.NET that claims to work, I am
working to modify it for C#, if anyone has a working version in C#
please let me know.

Don

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Reply With Quote
  #4  
Old   
Ben Strackany
 
Posts: n/a

Default Re: Advice on cache design - 11-09-2004 , 05:22 PM



Can you write a stored procedure that encapsulates the ~20 database calls
you're doing? Then at least you're only calling the DB once instead 20
times.

--
Ben Strackany
www.developmentnow.com

<a href="http://www.developmentnow.com">dn</a>


"Stephen Woolhead" <stephen (AT) perfectphase (DOT) com> wrote

Quote:
Hi all, I am looking for some advice on how to implement a caching
solution
for use in my asp.net app.

I have a function that returns a simple true or false, but to get the
answer
needs to execute appox 20 queries to the database. This function gets
called a lot so I want to store the result in a cache. The problem is
that
the function is dependent on three parameters two of which are indexes of
lists stored in the database, a change to any of these lists invalidates
the
function's cached results.

What I need to implement is a cache where I can invalidate all cache items
that have a dependency on a certain list index.

At the moment, I have a database table which looks like this

MembershipListID, AccessListID, OperationID, result, timestamp

Everytime this function is called, I check to see if there is a result in
the cache table, if the is I use it otherwise I do the work and an entry
to
the cache table.

If the value of one of the lists changes I issue a delete for all records
that use that list ID.

Now I would like to move this to the ASP.NET cache for a bit more speed,
and
ease of management but am not sure how to.

My best idea at the moment is to create dummy cache entries for each of
the
list indexes and then create a cache dependency on these keys for each
result that goes into the cache, something like this.

MembershipListID = 4
AccessListID = 8
OperationID = 3
Result = true

So I would add the following place holders for creating cache dependencies

MLID#4
ALID#8

I would then add another cache item with the key FR#4#8#3 with the value
true and cache dependencies on MLID#4 and ALID#8

When one of the lists changes, I would remove the place holder key from
the
cache, for example MLID#4 and that would remove all the function results
dependant on it.

Is this the best way to solve something like this?

Also while I have your attention, what is the accepted way to namespace
your
cache entries? I don't want my cache entries to get confused with another
assemleblies data, so what do I do? Pre/post fix the key with the
assembly
name or public key?

Thanks

Stephen





Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.