Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > app vars and cache vars

Reply
Thread Tools

app vars and cache vars

 
 
Jon
Guest
Posts: n/a
 
      12-14-2004
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


 
Reply With Quote
 
 
 
 
Karl Seguin
Guest
Posts: n/a
 
      12-14-2004
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
>
>



 
Reply With Quote
 
 
 
 
Kevin Spencer
Guest
Posts: n/a
 
      12-14-2004
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:(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > 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
> >
> >

>
>



 
Reply With Quote
 
Jon
Guest
Posts: n/a
 
      12-14-2004
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:(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> 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
>>
>>

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Use self.vars in class.method(parameters, self.vars) caccolangrifata Python 18 07-22-2011 10:22 PM
How do I declare global vars or class vars in Python ? Linuxguy123 Python 7 02-20-2009 06:45 PM
no-cache - need to reload page from server and not the cache John HTML 2 10-29-2006 05:35 PM
What's the purpose of the helper cache and is there a way to just turn off helper cache-ing? kevin Ruby 1 07-21-2006 03:42 AM
Public Sub/vars in web app? thdevdex ASP .Net 2 08-18-2003 03:57 PM



Advertisments