Cache Questions

  • Thread starter Thread starter Zeljko
  • Start date Start date
Z

Zeljko

Hi,

I was playing with the cache class (caching data, not fragments or
pages). It seems to be a very usefull feature, but I didn't manage to
find an explanation on how it works behind the scene. Except being
plain curious about it, I have a few concrete reasons for wanting to
know that, like:

- Can I store instance of a class in the cache ? If I can, what will
happen if one session pulls that object out of the cache and calls
it's method which changes content of the object ? Will the change be
visible globally ? I suppose yes ?
- Does that class need to be marked Serializable ? I noticed that if
you want to store object in the StateBag, that object must be marked
Serializable. Does something similar apply to Cache ? I tried that on
my machine and had no problems, but haven't tried it yet on the web
server - need to verify that other users see changes made to the
cached class...

Zeljko
 
Hi,

The cache is eventually hash table in the application session domain
holding pairs of keys and objects. The different between cache and
application state is that cache comes with mechanism of dependency that
let you set relationship between cache expiration by setting
dependencies. (basically Cache class call CacheInternal that use
CacheEntry which implement hash table). All this story was just to show
you that cache is eventually hashtable so every change that you made
will be visible globally. You can conclude from this implementation that
cache doesn’t required serialization. Unlike statebag or session that
requires serialization if the object is going to be preserve on another
application domain, process or machine cache is always maintains in
application app domain thus doesn’t required serialization.

Natty Gur[MVP]

blog : http://weblogs.asp.net/ngur
Mobile: +972-(0)58-888377
 
Thanks for the info - you helped me a lot. However - I do have one
more question - what is application domain in the context of ASP .NET
? Application object ? IIS ? Is there any relation between IIS
application protection settings and scope of application domain ?

E.g. if application protection is set to Low (IIS process) - does that
mean that all applications are running in the same domain and cache
will be shared by all applications on the server ?

Thanks,

Zeljko
 
Hi,

Every web application that you set via IIS is application domain in the
aspet_wp / w3wp process. asp.net can recycle one of the applications by
restarting application domain ( If you wonder, you can't).

IIS 5 and IIS 6 have different relationship with asp.net process. IIS 5
get requests and use pipes to transfer request to aspnet_wp process
while in windows 2003 w3wp has its own http.sys and receive its request
directly. So while IIS 5.0 isolation can impact IIS part of handling the
request, IIS 6.0 doesn’t have any impact at all. Anyway isolation level
in aspnet_wp based on application domain. IIS 6.0 introduce application
pools that let you isolate application on process base.

Natty Gur[MVP]

blog : http://weblogs.asp.net/ngur
Mobile: +972-(0)58-888377
 
Back
Top