The lifecycle of Cache

E

Enosh Chang

Hi all:

I want to use System.Web.Caching.Cache in my web application, but I want to
know the lifecycle of Cache (depending on Page, Session or Application ...).
Thanks!

Enosh
 
J

Juan T. Llibre

re:
I want to know the lifecycle of Cache (depending on Page, Session or Application ...).

One instance of the Cache class is created per application domain,
and it remains valid as long as the application domain remains active.

You can insert items in the Cache :

1. with a key dependency ( When a key dependency changes, the object becomes invalid
and is removed from the cache ). You can opt to have it replaced with a new key dependency.

2. with a file dependency ( When any dependency changes, the object becomes invalid
and is removed from the cache ). You can opt to have it replaced with a new dependency.

3. With a SQLDependency, based on a SQL Server table or query.
When the data changes, so does the cache.

4. with an absoluteExpiration time

5. with a slidingExpiration time

You can also set up a notification when the item is removed from the cache.

See :
http://msdn2.microsoft.com/en-us/library/4y13wyk9.aspx

http://msdn2.microsoft.com/en-us/library/system.web.caching.aspx

http://msdn2.microsoft.com/en-us/library/system.web.caching.cache.aspx

http://msdn2.microsoft.com/en-us/library/system.web.caching.sqlcachedependency.aspx

For specific usage, see Cache Insert :
http://msdn2.microsoft.com/en-us/library/system.web.caching.cache.insert.aspx

There's other types of caching, like Output Caching.
You can control its duration with the "Duration parameter :

<%@ OutputCache Duration="#ofseconds"

See :
http://msdn2.microsoft.com/en-us/library/hdxfb6cy.aspx

You can also use partial caching ( caching user controls, for example ):

See:
http://msdn2.microsoft.com/en-us/library/system.web.ui.partialcachingattribute.duration.aspx
http://msdn2.microsoft.com/en-us/library/system.web.ui.partialcachingattribute.aspx

As you can see, there's a number of answers to your question,
depending on the type of caching you perform.

Read the supplied links and decide which type of caching,
and for which duration, is the caching you want to implement.
 
K

Karl Seguin [MVP]

Juan's answer is good. Just thought I'd mention that the word you are
looking for is "scope", not "lifecycle".

Karl
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top