473,399 Members | 2,858 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

app vars and cache vars

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
3 1534
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: james | last post by:
I am new to php and need some help getting the session variables into include files. (after-thought, Sorry for the drawn out post but I really, really need help....;) Here's what I'm doing.. ...
4
by: Al | last post by:
Is possible to terminate all session variable created without closing the browser I do not want users to click on BACK button on browser or paste the url link in the http:// and shows the record...
1
by: Tim | last post by:
Hi, We are downloading a few thousand rows of data for users to choose from and need to speed up the operation. The data is related in four levels. The current design allows the user to select...
1
by: thdevdex | last post by:
I'm new to the web forms world (ASP.Net) but not vb and am converting a vb6 windows app to the web. If I create public subroutines at a module level, is this a problem in a server based app? Will...
4
by: Keith Chadwick | last post by:
I am having some trouble referencing an Application("myVar") variable from within a module.vb file on my ASP.NET site. According to the documentation I should be able to reference...
2
by: Lee | last post by:
I've been programming with Delphi for the past 4 years or so and while Delphi does allow globals, I use them very judiciously. I say that I *do* use them because I think that in some cases they...
19
RMWChaos
by: RMWChaos | last post by:
Previously, I had used independent JSON lists in my code, where the lists were part of separate scripts. Because this method did not support reuse of a script without modification, I decided to...
6
by: goodguyjam | last post by:
Hi all, I'm having trouble with mysql. I've just finished my php coding for HTTP authentication and with some help am now getting a login window pop up whenever I click on a link on my website...
5
by: Ross | last post by:
Forgive my newbieness - I want to refer to some variables and indirectly alter them. Not sure if this is as easy in Python as it is in C. Say I have three vars: oats, corn, barley I add them...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.