By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,223 Members | 1,371 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,223 IT Pros & Developers. It's quick & easy.

app vars and cache vars

P: n/a
Jon
I have a couple of tables I want to load into a dataset and keep around
pretty much forever, although they will need to be refreshed every so often.

I can either put the dataset into an Application("myDataset") var or I can
put it into the cache, Cache("myDataset"), both are universally available to
my app, except in Global.asax, only Application() vars are available (or it
seems that way on my machine, at least).

I thought it would be better practice to use the cache, but I cannot do so
if I want to load the data in Application_Start. If I want to do that, I
need to use Application() vars.

Does it really matter whether I use app or cache vars? I know there's no
hard rules on when to use one and when to use the other...at least not that
I've seen. Everyone has their own ideas on that.

My questions:
1. When do you recommend cache over app vars?
2. Is there any performance difference between the two?
3. If using cache vars when is the best time to populate them?

Thank you!

--
********************************
Jon
Nov 19 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
This might be a little extreme, but hopefully everyone would answer
something along the same lines:
Never use Application....it forces the item in memory even when there are
memory constraints on the system. .Net is far better at managing its memory
than you can ever dream to be. This isn't as true for simple object, but
for a dataset, which could be huge, it's very important.

Use the cache which lets .Net manage its memory. Note that iwth the cache
you aren't sure that the data will be there (which is why you want to use
it)...so you need to check if its in the cache and if not, get the data and
re-store it.

When is the best time to populate them? Lazily populate stuff as its
needed. This sort of stuff should be abstracted away in a business layer
anyways...

public function GetAllSomething() as DataSet
string cacheKey = "GetAllSOmething"
DataSet ds = (DataSet) HttpRuntime.Cache[cacheKey];
if (ds == null){
ds = DataBase.GetMySomething()
HttpRuntime.Cache.Insert(cacheKey, ds, null,
DateTime.Now.AddHours(2), TimeSpan.Zero);
}
return ds
end function

that mix of c# and vb should be all you need. Whenever you need the
dataset, simply call GetAllSomething()

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Jon" <ru******@msn.com> wrote in message
news:10*************@corp.supernews.com...
I have a couple of tables I want to load into a dataset and keep around
pretty much forever, although they will need to be refreshed every so often.
I can either put the dataset into an Application("myDataset") var or I can
put it into the cache, Cache("myDataset"), both are universally available to my app, except in Global.asax, only Application() vars are available (or it seems that way on my machine, at least).

I thought it would be better practice to use the cache, but I cannot do so
if I want to load the data in Application_Start. If I want to do that, I
need to use Application() vars.

Does it really matter whether I use app or cache vars? I know there's no
hard rules on when to use one and when to use the other...at least not that I've seen. Everyone has their own ideas on that.

My questions:
1. When do you recommend cache over app vars?
2. Is there any performance difference between the two?
3. If using cache vars when is the best time to populate them?

Thank you!

--
********************************
Jon

Nov 19 '05 #2

P: n/a
Actually, you can set the Cache timeout for individual items to never
expire. If you do this, you don't have to worry about Cache items expiring
or disappearing, unless the app recycles.

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

"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:es**************@TK2MSFTNGP10.phx.gbl...
This might be a little extreme, but hopefully everyone would answer
something along the same lines:
Never use Application....it forces the item in memory even when there are
memory constraints on the system. .Net is far better at managing its memory than you can ever dream to be. This isn't as true for simple object, but
for a dataset, which could be huge, it's very important.

Use the cache which lets .Net manage its memory. Note that iwth the cache
you aren't sure that the data will be there (which is why you want to use
it)...so you need to check if its in the cache and if not, get the data and re-store it.

When is the best time to populate them? Lazily populate stuff as its
needed. This sort of stuff should be abstracted away in a business layer
anyways...

public function GetAllSomething() as DataSet
string cacheKey = "GetAllSOmething"
DataSet ds = (DataSet) HttpRuntime.Cache[cacheKey];
if (ds == null){
ds = DataBase.GetMySomething()
HttpRuntime.Cache.Insert(cacheKey, ds, null,
DateTime.Now.AddHours(2), TimeSpan.Zero);
}
return ds
end function

that mix of c# and vb should be all you need. Whenever you need the
dataset, simply call GetAllSomething()

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Jon" <ru******@msn.com> wrote in message
news:10*************@corp.supernews.com...
I have a couple of tables I want to load into a dataset and keep around
pretty much forever, although they will need to be refreshed every so often.

I can either put the dataset into an Application("myDataset") var or I can put it into the cache, Cache("myDataset"), both are universally available to
my app, except in Global.asax, only Application() vars are available (or

it
seems that way on my machine, at least).

I thought it would be better practice to use the cache, but I cannot do

so if I want to load the data in Application_Start. If I want to do that, I need to use Application() vars.

Does it really matter whether I use app or cache vars? I know there's no hard rules on when to use one and when to use the other...at least not

that
I've seen. Everyone has their own ideas on that.

My questions:
1. When do you recommend cache over app vars?
2. Is there any performance difference between the two?
3. If using cache vars when is the best time to populate them?

Thank you!

--
********************************
Jon


Nov 19 '05 #3

P: n/a
Jon
Thanks, that's a good guideline in my opinion. I hadn't realized that using
the app vars was different on memory, etc.
"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:es**************@TK2MSFTNGP10.phx.gbl...
This might be a little extreme, but hopefully everyone would answer
something along the same lines:
Never use Application....it forces the item in memory even when there are
memory constraints on the system. .Net is far better at managing its
memory
than you can ever dream to be. This isn't as true for simple object, but
for a dataset, which could be huge, it's very important.

Use the cache which lets .Net manage its memory. Note that iwth the cache
you aren't sure that the data will be there (which is why you want to use
it)...so you need to check if its in the cache and if not, get the data
and
re-store it.

When is the best time to populate them? Lazily populate stuff as its
needed. This sort of stuff should be abstracted away in a business layer
anyways...

public function GetAllSomething() as DataSet
string cacheKey = "GetAllSOmething"
DataSet ds = (DataSet) HttpRuntime.Cache[cacheKey];
if (ds == null){
ds = DataBase.GetMySomething()
HttpRuntime.Cache.Insert(cacheKey, ds, null,
DateTime.Now.AddHours(2), TimeSpan.Zero);
}
return ds
end function

that mix of c# and vb should be all you need. Whenever you need the
dataset, simply call GetAllSomething()

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Jon" <ru******@msn.com> wrote in message
news:10*************@corp.supernews.com...
I have a couple of tables I want to load into a dataset and keep around
pretty much forever, although they will need to be refreshed every so

often.

I can either put the dataset into an Application("myDataset") var or I
can
put it into the cache, Cache("myDataset"), both are universally available

to
my app, except in Global.asax, only Application() vars are available (or

it
seems that way on my machine, at least).

I thought it would be better practice to use the cache, but I cannot do
so
if I want to load the data in Application_Start. If I want to do that, I
need to use Application() vars.

Does it really matter whether I use app or cache vars? I know there's no
hard rules on when to use one and when to use the other...at least not

that
I've seen. Everyone has their own ideas on that.

My questions:
1. When do you recommend cache over app vars?
2. Is there any performance difference between the two?
3. If using cache vars when is the best time to populate them?

Thank you!

--
********************************
Jon


Nov 19 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.