> I should've read the docs more carefully - there's only one cache instance
> per application domain.
Where did you read that? I have found nothing which states clearly one way
or another.
> But still, I don't understand what exactly you'd
> want to pool in a cache,
Nothing. I'm just trying to understand how the cache stores what it owns. A
pool is one of several options.
> are you talking about having multiple copies of all
> the cached objects?
One theory is that there may be multiple independent copies of the Cache
object. That could be one reason (aside from memory management, etcetera)
the existence of items stored in the cache is unreliable and that it is
necessary to check for null first and re-create data as needed.
> And only be able to access each copy from one
> client/thread, like database connections (where pooling makes sense as each
> connection cannot be shared across multiple concurrent threads). I still do
> not understand why would you even want to pool cache.
Here is a simple scenario. I have a DataSet which contains two tables:
Countries and Provinces. Each row in the Provinces table is linked to a
Country in the Countries table (your basic master/detail relationship). The
items in the provinces table are loaded on-demand so the states in the USA
are not loaded until an end-user needs to see the states available in the
USA.
Now here is the dilemma: How do I do these updates? If the Cache object is
instanced per-thread or is pooled, then I have no worries. I can simply get
the DataSet (reference_ from the Cache then fill/update it as necessary
without concerning myself about how other users will cause interaction with
the data because they will be executing in a separate context with a
separate instance of a Cache object. However, if the Cache is truly Global
(like the Application object) then I must ensure that the same set of
provinces isn't loaded twice in the same instance of the dataset.
The benefit of pooling is not having to worry about context: once an item is
drawn from the pool, no one else can see it (much less access it). The
drawback is extra memory consumption.
The worst thing, however, is not knowing which the Cache does! Each scenario
requires a different approach for manipulation and I cannot find any
documentation of which approach to use nor why.
Take a common example:
DataSet MyData = Cache["MyData"];
if(MyData == null){
MyData = new MyDataSet();
SomeAdapter.Fill(MyData);
Cache["MyData"] = MyData;
}
Now imagine this code executing simultaneously in two separate threads of
the same application. What goes where? Do two datasets get created/filled,
but only one stored? Or do two get stored - one in each separate context?
> Jerry

Signature
-Jimmy
Jimmy [Used-Disks] - 10 Nov 2003 14:59 GMT
I've started a new thread with the example.

Signature
-Jimmy
Jerry III - 11 Nov 2003 07:07 GMT
Sorry it took me so long to reply:
> > I should've read the docs more carefully - there's only one cache instance
> > per application domain.
>
> Where did you read that? I have found nothing which states clearly one way
> or another.
http://msdn.microsoft.com/library/en-us/cpref/html/frlrfsystemwebcachingcach
eclasstopic.asp - the Cache class documentation would seem like the very
obvious place to search for an information like this.
> Here is a simple scenario. I have a DataSet which contains two tables:
> Countries and Provinces. Each row in the Provinces table is linked to a
> Country in the Countries table (your basic master/detail relationship). The
> items in the provinces table are loaded on-demand so the states in the USA
> are not loaded until an end-user needs to see the states available in the
> USA.
You just cache the list of counties for each state. Like this:
string State; // Put your state selection here
string[] CountyList = (string[])Cache["state-" + State];
if( CountyList == null )
{
// Load the list of counties here
Cache["state-" + State] = CountyList; // You should rpobably use
Insert
}
> Now here is the dilemma: How do I do these updates? If the Cache object is
> instanced per-thread or is pooled, then I have no worries. I can simply get
[quoted text clipped - 25 lines]
> the same application. What goes where? Do two datasets get created/filled,
> but only one stored? Or do two get stored - one in each separate context?
It will not work, there is one cache shared accross all requests (well,
across one application domain). You need to cache data that will be the same
for each request, like list of counties in each state, not session state
information. If you really want to go that way store it in a session - but
in this case it makes absolutely no sense as the list of counties wil be the
same in a given state for alll requests (and if it wasn't, let's say due to
user restrictions then it has no place in the cache).
Remember, caching only makes sense if it's reused over a lot of requests.
Don't put your state objects there.
> > Jerry
>
> --
> -Jimmy
Jimmy [Used-Disks] - 11 Nov 2003 14:15 GMT
http://msdn.microsoft.com/library/en-us/cpref/html/frlrfsystemwebcachingcach
> eclasstopic.asp - the Cache class documentation would seem like the very
> obvious place to search for an information like this.
Hey Jerry, thanks for the answer. Somehow I must have missed this page
(don't know how though! <g>).

Signature
-Jimmy
Bored Stiff - 11 Nov 2003 10:14 GMT
> DataSet MyData = Cache["MyData"];
> if(MyData == null){
> MyData = new MyDataSet();
> SomeAdapter.Fill(MyData);
> Cache["MyData"] = MyData;
> }
> Now imagine this code executing simultaneously in two
> separate threads of
> the same application. What goes where? Do two datasets
> get created/filled,
> but only one stored? Or do two get stored - one in each
> separate context?
Look at the MSDN documentation for the Cache class: "... One instance of
this class is created per application domain ...".
In the above scenario two get created/filled and one reference is
stored, overwriting any previous reference.
Note that in addition to HttpContext.Cache and Page.Cache, you can
reference the cache for your application domain using the static
property HttpRuntime.Cache.