I thought this warranted a new thread.
Yesterday I asked about access relatively static content...is it better to
read from the DB, or just grab a text file. It was suggested that I use the
DB and look into the Application Cache settings.
I found a good article here: http://www.developer.com/net/net/article.php/1477771
It mentions that, at least with files, you can set the cache to retain the
information until the file is updated, at which time it will access it again
and re-cache. Can the same be done for a DB? My guess is no, since to check
for the update, it'd have to access the DB, and if it has to do that, it
might as well grab the data while its there.
The catch is that the text in question, though it won't change often, IS
editable via an admin tool and when it's changed, the client would obviously
want to see the change take place...instead of waiting for the cache to
expire. I could set the cache to something like 5 minutes, which might be
acceptable.
Anyways, the final thought was to keep the data in the DB for editing
purposes, but upon each 'save', also write out a text file and then read
that text file in via asp, setting the cache to renew only when the file is
again changed. Does anyone see a problem with that logic?
-Darrel 5 1654
ASP.Net 2.0 when used with SQL Server 2005 will support cache invalidation.
I believe there are ways to do it in ASP.Net 1.1 but they aren't
straightforward
( http://msdn.microsoft.com/library/de...-us/dnaspnet/h
tml/asp11022004.asp)
Caching something for 5 minutes, which is read a lot in that time will
actually give you a VERY good performance boost....if you have 10 page views
per second, and 10% of those use that data, you'll save like 299 database
calls (pretty good!)
An alternative to writing a file and putting a dependency on it, is to
simply have a nice business layer which clears the cache on update, here's
some pseudo-code:
Function GetData
If NOT in cache THEN
Get From DataBase
Store In Cache
End IF
Return Data
End Function
Function UpdataData
Update The Data
Clear Cache
End function
you can even do something like
public DataSet GetData(){
return GetData(false);
}
private DataSet GetData(bool forceRefresh){
string cacheKey = "GetAllData";
DataSet ds = (DataSet) HttpRuntime.Cache[cacheKey];
if (ds == null || forceRefresh){
//get data
//store in cache
}
return ds;
}
public void UpdateData(){
//updateData
GetData(true);
}
this code will automatically refetch the new data and store it in the cache
when you update...sweet :)
Karl
--
MY ASP.Net tutorials http://www.openmymind.net/
"Darrel" <no*****@nospam.com> wrote in message
news:uW*************@TK2MSFTNGP14.phx.gbl... I thought this warranted a new thread.
Yesterday I asked about access relatively static content...is it better to read from the DB, or just grab a text file. It was suggested that I use
the DB and look into the Application Cache settings.
I found a good article here:
http://www.developer.com/net/net/article.php/1477771
It mentions that, at least with files, you can set the cache to retain the information until the file is updated, at which time it will access it aga
in and re-cache. Can the same be done for a DB? My guess is no, since to
check for the update, it'd have to access the DB, and if it has to do that, it might as well grab the data while its there.
The catch is that the text in question, though it won't change often, IS editable via an admin tool and when it's changed, the client would
obviously want to see the change take place...instead of waiting for the cache to expire. I could set the cache to something like 5 minutes, which might be acceptable.
Anyways, the final thought was to keep the data in the DB for editing purposes, but upon each 'save', also write out a text file and then read that text file in via asp, setting the cache to renew only when the file
is again changed. Does anyone see a problem with that logic?
-Darrel
> Caching something for 5 minutes, which is read a lot in that time will actually give you a VERY good performance boost....if you have 10 page views per second, and 10% of those use that data, you'll save like 299 database calls (pretty good!)
Yea...but there's no way this site is going to see enough traffic to really
see the benefit of that. ;o)
Still, that looks like perhaps the most viable option right now. These
snippets of text will be updated so infrequently that the client can easily
wait 5 minutes every now and again.
Function UpdataData Update The Data Clear Cache End function
Ah...OK, that makes sense. Instead of writing to a file, simply tell the
cache to come and refresh itself.
you can even do something like public void UpdateData(){ //updateData GetData(true); }
I'm a little confused on that one. Is the DS a global one? I guess the
question is how/where do you set the 'update key' from the usercontrol that
updates the data so that the usercontrol that gets the data can check for
it? Is that some sort of globally read variable?
-Darrel
DataSet isn't a global variable...this is a business layer...whenever you
want the data, you call the function GetData() which takes care of checking
the cache, getting the data from the database if not in the cache and
storing it in the cache, then returning it.
function DataSet GetData(bool forceRefresh){
string cacheKey = "GetData";
DataSet ds = (DataSet)HttpRuntime.Cache[cacheKey];
if (ds == null || forceRefresh){
ds = GetDataFromDataBase();
HttpRuntime.Cache.Insert(cacheKey, ds, null,
DateTime.Now.AddHours(12), TimeSpan.Zero);
}
return ds;
}
The user control simply calls GetData() whenever it needs the data:
MyRepeater.DataSource = GetData();
MyRepeater.DataBind();
or
DataSet ds = GetData();
for (int i = 0; i < ds.Tables[0].Rows.Count; ++i){
///
}
or whatever you do with it.
GetData() will always have fresh data in it, because when your other user
control calls UpdateData(), it'll cause the cache to get wiped and GetData()
will go hit the database..
Karl
--
MY ASP.Net tutorials http://www.openmymind.net/
"Darrel" <no*****@nospam.com> wrote in message
news:eR**************@TK2MSFTNGP10.phx.gbl... Caching something for 5 minutes, which is read a lot in that time will actually give you a VERY good performance boost....if you have 10 page views per second, and 10% of those use that data, you'll save like 299
database calls (pretty good!) Yea...but there's no way this site is going to see enough traffic to
really see the benefit of that. ;o)
Still, that looks like perhaps the most viable option right now. These snippets of text will be updated so infrequently that the client can
easily wait 5 minutes every now and again.
Function UpdataData Update The Data Clear Cache End function Ah...OK, that makes sense. Instead of writing to a file, simply tell the cache to come and refresh itself.
you can even do something like public void UpdateData(){ //updateData GetData(true); }
I'm a little confused on that one. Is the DS a global one? I guess the question is how/where do you set the 'update key' from the usercontrol
that updates the data so that the usercontrol that gets the data can check for it? Is that some sort of globally read variable?
-Darrel
> GetData() will always have fresh data in it, because when your other user control calls UpdateData(), it'll cause the cache to get wiped and GetData() will go hit the database..
That was the question I had.
You have this:
Function UpdataData
Update The Data
Clear Cache
End function
But what, exactly is 'cache'? In otherwords, how to you reference a specific
cache to tell it to clear? Is the cache a global object of some sort that
can be referenced between controls?
-Darrel
Well, you saw how I got something from the cache:
string cacheKey = "GetData";
DataSet ds = (DataSet)HttpRuntime.Cache[cacheKey];
and how I put something in the cache:
HttpRuntime.Cache.Insert(cacheKey, ds, null, DateTime.Now.AddHours(12),
TimeSpan.Zero);
You clear something from the cache via:
HttpRuntime.Cache.Remove("KEY");
the "KEY" is the same as the cacheKey above...you could make it a private
const member of your class:
public class DataUtility{
private const string cacheKey = "GetData";
..
...
}
and use this cacheKey across your classes..
As for the cache itself, HttpRuntime.Cache is created and maintained by
ASP.Net. When you are in a page, you can simply use Cache or Page.Cache to
access it. You only need to use HttpRuntime.Cache when you aren't in a
page/user control (when ur in just a normal class)...but they refer to the
same thing.
Some resources: http://openmymind.net/DataStorage/index.html#cache http://msdn.microsoft.com/library/de...classtopic.asp http://www.developer.com/net/net/article.php/1477771
Karl
--
MY ASP.Net tutorials http://www.openmymind.net/
"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:%2****************@TK2MSFTNGP12.phx.gbl... DataSet isn't a global variable...this is a business layer...whenever you want the data, you call the function GetData() which takes care of
checking the cache, getting the data from the database if not in the cache and storing it in the cache, then returning it.
function DataSet GetData(bool forceRefresh){ string cacheKey = "GetData"; DataSet ds = (DataSet)HttpRuntime.Cache[cacheKey]; if (ds == null || forceRefresh){ ds = GetDataFromDataBase(); HttpRuntime.Cache.Insert(cacheKey, ds, null, DateTime.Now.AddHours(12), TimeSpan.Zero); } return ds; }
The user control simply calls GetData() whenever it needs the data:
MyRepeater.DataSource = GetData(); MyRepeater.DataBind();
or
DataSet ds = GetData(); for (int i = 0; i < ds.Tables[0].Rows.Count; ++i){ /// }
or whatever you do with it.
GetData() will always have fresh data in it, because when your other user control calls UpdateData(), it'll cause the cache to get wiped and
GetData() will go hit the database..
Karl
-- MY ASP.Net tutorials http://www.openmymind.net/
"Darrel" <no*****@nospam.com> wrote in message news:eR**************@TK2MSFTNGP10.phx.gbl... Caching something for 5 minutes, which is read a lot in that time will actually give you a VERY good performance boost....if you have 10 page views per second, and 10% of those use that data, you'll save like 299 database calls (pretty good!)
Yea...but there's no way this site is going to see enough traffic to
really see the benefit of that. ;o)
Still, that looks like perhaps the most viable option right now. These snippets of text will be updated so infrequently that the client can easily wait 5 minutes every now and again.
Function UpdataData Update The Data Clear Cache End function
Ah...OK, that makes sense. Instead of writing to a file, simply tell the cache to come and refresh itself.
you can even do something like public void UpdateData(){ //updateData GetData(true); }
I'm a little confused on that one. Is the DS a global one? I guess the question is how/where do you set the 'update key' from the usercontrol that updates the data so that the usercontrol that gets the data can check
for it? Is that some sort of globally read variable?
-Darrel
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
by: stefano mostarda |
last post by:
Hi there,
I have a question.
In my application I have a table which is frequently used to fill a combo. I
want to store it in the application or cache object. it is never updated.
What's...
|
by: spammy |
last post by:
hi all,
im currently writing an ASP.net front end to display data found in an XML
file. the XML file is quite large (700k or so), and so takes a while to
load. it will be changing around every...
|
by: Greg Collins [MVP] |
last post by:
Hi, I couldn't find what I was looking for by searching the newsgroup, but perhaps these have already been discussed somewhere. This is a bit long with a lot of interrelated questions.
What I've...
|
by: Trevor Andrew |
last post by:
Hi There,
Hopefully this isn't too difficult a question to express here. I have a 3
tier application.
1. Presentation Tier: ASP.NET web application. 2. Middle Tier: ASP.NET Web
Services that...
|
by: Fred Nelson |
last post by:
Hi:
This is probably a newby question however I can't figure it out!
I'm trying to use application data caching in a web application. I have
read an article on 4 guys from rolla that shows...
|
by: LeAnne |
last post by:
My question is to do with scalability and the location for storate of cache,
session, viewstate and application data.
Application - Data is stored in memory (in process)
Session - Data is stored...
|
by: J055 |
last post by:
Hi
The following code works on my develeopment machine using the VS web server.
When I run the application on 2 other Windows 2003/IIS 6 servers no caching
seems to take place at all. Can...
|
by: Kemmylinns12 |
last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
|
by: antdb |
last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine
In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
|
by: Arjunsri |
last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and credentials and received a successful connection...
|
by: Matthew3360 |
last post by:
Hi,
I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
|
by: Oralloy |
last post by:
Hello Folks,
I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA.
My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
|
by: Carina712 |
last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
|
by: BLUEPANDA |
last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
|
by: Ricardo de Mila |
last post by:
Dear people, good afternoon...
I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control.
Than I need to discover what...
|
by: jack2019x |
last post by:
hello, Is there code or static lib for hook swapchain present?
I wanna hook dxgi swapchain present for dx11 and dx9.
| |