Using the Cache object vs. letting .net or IIS handle it

D

darrel

I had a conversation with a friend today.

I'm working on a project where I have an XML file that stores the site
structure and some page-centric variables. I have a handful of controls that
will be reading from this XML file.

My initial reaction was to load the XML file once, and then set it to a
cache object, so that it's cached and only updated if the file is updated on
the server.

He said that was unecessary, as IIS/.net will cache frequently accessed
files automatically for you.

Any thoughts on that?

-Darrel
 
K

Kevin Spencer

You had the right idea in the first place. Your friend is mixing up caching
with caching. ;-)

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Neither a follower nor a lender be.
 
D

darrel

You had the right idea in the first place. Your friend is mixing up
caching
with caching. ;-)

Hmm...;o)

So, what, exactly, does IIS/.net cache by default vs. what should I
explicitly cache?

-Darrel
 
K

Karl Seguin

Aye...you are right..

The O/S will likely "cahce" files that are being frequently access to savel
save the disk I/O work...but this is really different than the type of
caching we are talking about (I'm not aware of .Net doing any automatic
caching btw). putting it int he Cache object specifically puts in in the
asp.net worker processes memory space...Besides, the O/S definion of what's
"frequent" could be like hundres of times per
second....where as ours could be like a couple times....what good are
friends for when you got newsgroups??

Karl
 
J

Juan T. Llibre

Well, you *could* argue that the compiled pages are "cached"
server-side, since no recompilation is needed to serve them,
but the primary benefit of caching is the substitution of database
retrievals, contents of XML-based data, etc.

Being able to load frequently-used data from memory,
instead of making data calls is the main benefit.
 
D

darrel

second....where as ours could be like a couple times....what good are
friends for when you got newsgroups??

;o)

I see...the main benefit is that I'm at the mercy of IIS or the OS itself
deciding what to cache vs. me being able to tell .net explicitely what to
cache.

Thanks!

-Darrel
 
D

darrel

TO expand upon the question...is there an upper limit of files I shouldn't
cache myself?

For instance, this site will have about 10 XML files and 3 or so XSLT files.
Is there any reason NOT to go ahead and set all of them to cache objects,
since they'll rarely change on the server (maybe once a week or so at most)?

-Darrel
 
J

Joe Fallon

I thought the web.config file was automatically cached so it was only read
once and there was no perofrmance hit when reading one of the values.
 
J

Juan T. Llibre

Web.config is read into memory when the application starts.

That is slightly different than using the Cache object, though.

You can cache pages, data fragments, all kinds of objects, etc.

You can also set database dependency, file, key,
time-based and expiration policies to update the cache.

ASP.NET 2.0 introduces a concept called post-cache substitution.
You'll love that feature ... ;-)
 
K

Kevin Spencer

Part of the problem here may be understanding the word "cache." Caching is
simply the process of storing data in memory somewhere. One might argue that
creating a variable is creating a cache. In other words, the word "cache" is
so general that unless you specify the cache you're talking about, it is
easy to get confused about which cache one is talking about.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Neither a follower nor a lender be.
 
K

Kevin Spencer

Well, I wouldn't put it that way. Think of it this way: IIS has its
responsibilities, which it manages all by itself. The OS has
responsibilities which it manages all by itself. And ou have
responsibilities which you must manage by yourself. You're not at the mercy
of IIS; you are freed from that responsibility.

I started out programming DOS with C. Back then, you even had to manage your
own peripheral drivers. Believe me, you don't want to go back there!

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Neither a follower nor a lender be.
 
K

Kevin Spencer

Think of cache as a wallet full of memory (cash). As long as the wallet is
big enough, put all the cash you need in it. After all, cash is always
faster than credit! ;-)

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Neither a follower nor a lender be.
 

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

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top