Groups | Blog | Home
all groups > asp.net caching > october 2004 >

asp.net caching : Caching multiple versions of a sql-query ...?



Koen Hoorelbeke
10/4/2004 8:21:01 PM
Hi there,

Here's the situation: I have a webservice that calls an sql query and
returns a table with data. This table doesn't change so much (actually very
little, maybe only once a month or so).

However it contains data for multiple countries/states. So when I need the
data, I have one parameter (the country). And thus the outcome of the query
can be as different as there are countries/states in the world.

So if I want to cache the output (put the dataset in the cache), I kind of
need a different cache-object for each possible country (and I don't know
which countries will be input parameters).

How do I do this best? Can I dynamically make cache objects?

Preferably I'd like to have a cache-object for each country. Get the dataset
out of it, and do my thing. But as I look at it now, it seems that I have to
manually define a cache-object for each country ... and that's really a no go
(I don't even know how many countries there are in the world :-).

And caching is a must, since this is a real busy webservice. Can't afford to
make that much unnecessary queries to my database-server (especially since
it's not really necessary).

How can I fix this? Any help, tips, suggestions would be very much
appreciated !

Thanks in advance.

Greetingz,
Koen Hoorelbeke
Koen Hoorelbeke
10/6/2004 7:25:03 AM
Well, the RAM isn't the problem ... but the filtering is ... now I have a
sql-query (stored proc) that is pretty complicated, and really can't see how
I would do that in the filtering. So that's really not an option.

I'm sure it must be feasible to cache different sets, I just don't know how.
Any link in the right direction would be helpfull!

Greetingz,
Koen Hoorelbeke
abc123@noemail.nospam


[quoted text, click to view]
BT
10/6/2004 12:38:59 PM
[quoted text, click to view]
[...]


If you have the resources/RAM, why don't you just cache the whole
information (all countries, useful fields) into one cahe item (either a
dataset or an array/arraylist), and then parse out of it the countries
required?


BT
10/6/2004 10:47:45 PM
- the outcome of the process/db for a country is an X (dataset? string?)
- each country returns a different value for X
- fill with X's an array.createinstance(typeof(X),countries_count)
- cache.insert(name,myarray)

Is there something I don't get?



[quoted text, click to view]
HG
10/19/2004 1:31:33 PM
Hi there

As you only have one parameter that changes, you could use the value of that
parameter as the key to a HashMap. The value would be the
DataSet/Query/Whatever you want

And then you put the whole HashMap in the Cache.

That way you can use the parameter coming to check if an instance already
exists in the HashMap and use that instance.
If not you just create it and put it there for later reuse.

Regards

Henrik


"Koen Hoorelbeke" <KoenHoorelbeke@discussions.microsoft.com> skrev i en
meddelelse news:01021061-A7B1-47E6-B867-6DD7BAFF694B@microsoft.com...
[quoted text, click to view]

Ersin Gençtürk
10/19/2004 2:42:37 PM
if I understood correct , you can try this

Cache["CountryList" + CountryName] = your object whatever it is

by doing this , if your webservice returns data based on country name , then
it will define different versions of your queries by caching them.then you
can make a if/else block like this

if (Cache["CountryList" + CountryName]!=null)
{
return(Cache["CountryList" + CountryName])
}
else
{
//read from datasource
.....
//put into cache
Cache["CountryList" + CountryName]!=your object
}

The only thing you should care about is to put a string that is uniqe (for
ex. country name)

"Koen Hoorelbeke" <KoenHoorelbeke@discussions.microsoft.com> wrote in
message news:01021061-A7B1-47E6-B867-6DD7BAFF694B@microsoft.com...
[quoted text, click to view]

AddThis Social Bookmark Button