HighTechTalks DotNet Forums  

Caching vs. Static member variables

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


Discuss Caching vs. Static member variables in the ASP.net Caching forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Steve James
 
Posts: n/a

Default Caching vs. Static member variables - 01-15-2005 , 04:05 PM






This may be a stupid question but...

What's the difference between using the ASP.NET Cache object and a class
that stores data in a static object. For example, the class below contains a
hashtable declared statically. This hashtable is accessible by all objects
that are part of the application.

public class MyCache

{

private static Hashtable hashtable = new Hashtable();

public MyCache()

{ }

public static Hashtable GetHashtable()

{

return hashtable;

}

}



The data being accessible by code such as:

string s = MyCache.GetHashtable()[ "CacheValue" ] as string;

s = s == null ? String.Empty : s;

this.TextBox1.Text = s;



Surely this provides the same functionality as the built-in Cache object
and, dare I say it, prefereable if you're wanting to write as environment
agnostic component as possible i.e. the class will behave the same
regardless of whether it is being called by a web/windows/console app.

Any comments and/or protestations would be welcomed.

Steve



Reply With Quote
  #2  
Old   
Joerg Jooss
 
Posts: n/a

Default Re: Caching vs. Static member variables - 01-16-2005 , 04:35 AM






Steve James wrote:

Quote:
This may be a stupid question but...

What's the difference between using the ASP.NET Cache object and a
class that stores data in a static object. For example, the class
below contains a hashtable declared statically. This hashtable is
accessible by all objects that are part of the application.

public class MyCache

{

private static Hashtable hashtable = new Hashtable();

public MyCache()

{ }

public static Hashtable GetHashtable()

{

return hashtable;

}

}



The data being accessible by code such as:

string s = MyCache.GetHashtable()[ "CacheValue" ] as string;

s = s == null ? String.Empty : s;

this.TextBox1.Text = s;



Surely this provides the same functionality as the built-in Cache
object and, dare I say it, prefereable if you're wanting to write as
environment agnostic component as possible i.e. the class will behave
the same regardless of whether it is being called by a
web/windows/console app.

Any comments and/or protestations would be welcomed.
There are quite a number of differences here:

-- The Cache is thread-safe (uses ReaderWriterLocks).

-- Cache entries can expire, can have scavenging priorities, can have
dependencies which may force them to be removed from the Cache, and the
Cache notifies you in case an entry is removed.

-- The Cache automatically scavenges entries if their lifetime has
expired or memory is low, thus is somewhat self-tuning.


Cheers,
--
http://www.joergjooss.de
mailto:news-reply (AT) joergjooss (DOT) de


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.