473,606 Members | 2,110 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Cache dataset and expire

Hi,

I am storing a dataset in cache, which is happening fine. I can easily
retrive it at postback from the cache, cast it to a dataset and reuse it.
However I have specified that the cache expire in 5 minutes like so.

If Not IsPostBack Then
BindMyDropDown( )
Else
Response.Write( "<hr>Cache Expires 5 minutes" &
DateTime.Now.Ad dSeconds(300) & "<hr>")
'If the cache had expired I would expect this line to cause an
error -- but it doesn't even if I cause postback after 15 minutes!!!
dsMyDataset = CType(Cache("ds "), DataSet)
Response.Cache. SetExpires(Date Time.Now.AddSec onds(300))
End If

I also set the cache expire in exactly the same way in the BindMyDropDown( )
function.
and place the dataset into the cache like so.

//code here
objConn.Open()
daMyDataAdapter .Fill(dsMyDatas et, "Customers" )
objConn.Close()
Cache.Insert("d s", dsMyDataset)
Response.Write( "<hr>Cache Expires 5 minutes" &
DateTime.Now.Ad dSeconds(300) & "<hr>")
Response.Cache. SetExpires(Date Time.Now.AddSec onds(300))

DropDownList1.D ataSource = dsMyDataset
DropDownList1.D ataValueField =
dsMyDataset.Tab les(0).Columns( 0).ToString
DropDownList1.D ataTextField =
dsMyDataset.Tab les(0).Columns( 1).ToString
DropDownList1.D ataBind()

when a button is clicked and a postback is caused the button handler
retrieves the cache dataset and rebinds it to a combo box.
I would have thought that if the page was posted back any later than 5
minutes that an error would occur because the cache had expired, but it
doesn't.
The lack of this error indicates to me that the cache is not expiring, but I
do not know what I am doing wrong.
How do I make the cache expire in 5 minutes.

cheers

martin


Nov 17 '05 #1
3 2845
You may be pulling some info from ViewState, which would pull the values
despite the cache being refreshed. Turn off ViewState to test this behavior.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

*************** *************** *************** *************** **********
Think Outside the Box!
*************** *************** *************** *************** **********
"martin" <ma***********@ hotmail.com> wrote in message
news:uA******** ******@tk2msftn gp13.phx.gbl...
Hi,

I am storing a dataset in cache, which is happening fine. I can easily
retrive it at postback from the cache, cast it to a dataset and reuse it.
However I have specified that the cache expire in 5 minutes like so.

If Not IsPostBack Then
BindMyDropDown( )
Else
Response.Write( "<hr>Cache Expires 5 minutes" &
DateTime.Now.Ad dSeconds(300) & "<hr>")
'If the cache had expired I would expect this line to cause an
error -- but it doesn't even if I cause postback after 15 minutes!!!
dsMyDataset = CType(Cache("ds "), DataSet)
Response.Cache. SetExpires(Date Time.Now.AddSec onds(300))
End If

I also set the cache expire in exactly the same way in the BindMyDropDown( ) function.
and place the dataset into the cache like so.

//code here
objConn.Open()
daMyDataAdapter .Fill(dsMyDatas et, "Customers" )
objConn.Close()
Cache.Insert("d s", dsMyDataset)
Response.Write( "<hr>Cache Expires 5 minutes" &
DateTime.Now.Ad dSeconds(300) & "<hr>")
Response.Cache. SetExpires(Date Time.Now.AddSec onds(300))

DropDownList1.D ataSource = dsMyDataset
DropDownList1.D ataValueField =
dsMyDataset.Tab les(0).Columns( 0).ToString
DropDownList1.D ataTextField =
dsMyDataset.Tab les(0).Columns( 1).ToString
DropDownList1.D ataBind()

when a button is clicked and a postback is caused the button handler
retrieves the cache dataset and rebinds it to a combo box.
I would have thought that if the page was posted back any later than 5
minutes that an error would occur because the cache had expired, but it
doesn't.
The lack of this error indicates to me that the cache is not expiring, but I do not know what I am doing wrong.
How do I make the cache expire in 5 minutes.

cheers

martin

Nov 17 '05 #2
I am not sure about datasets but with datatables and dataviews, if the cache
is empty it just returns nothing but does not generate an error. You can see
exactly what is in the cache by using the following

dim strCacheContent s as String
dim objItem as DictionaryEntry
dim strName as String
For Each objItem In Cache
strName = objItem.Key.tos tring()
strCacheContent s = "key=" & strName & "<br />"
Response.Write( strCacheContent s)
strCacheContent s = "value=" & Convert.ToStrin g(objItem.Value ) & "<br/>"
Response.Write( strCacheContent s)

Next
"martin" <ma***********@ hotmail.com> wrote in message
news:uA******** ******@tk2msftn gp13.phx.gbl...
Hi,

I am storing a dataset in cache, which is happening fine. I can easily
retrive it at postback from the cache, cast it to a dataset and reuse it.
However I have specified that the cache expire in 5 minutes like so.

If Not IsPostBack Then
BindMyDropDown( )
Else
Response.Write( "<hr>Cache Expires 5 minutes" &
DateTime.Now.Ad dSeconds(300) & "<hr>")
'If the cache had expired I would expect this line to cause an
error -- but it doesn't even if I cause postback after 15 minutes!!!
dsMyDataset = CType(Cache("ds "), DataSet)
Response.Cache. SetExpires(Date Time.Now.AddSec onds(300))
End If

I also set the cache expire in exactly the same way in the BindMyDropDown( ) function.
and place the dataset into the cache like so.

//code here
objConn.Open()
daMyDataAdapter .Fill(dsMyDatas et, "Customers" )
objConn.Close()
Cache.Insert("d s", dsMyDataset)
Response.Write( "<hr>Cache Expires 5 minutes" &
DateTime.Now.Ad dSeconds(300) & "<hr>")
Response.Cache. SetExpires(Date Time.Now.AddSec onds(300))

DropDownList1.D ataSource = dsMyDataset
DropDownList1.D ataValueField =
dsMyDataset.Tab les(0).Columns( 0).ToString
DropDownList1.D ataTextField =
dsMyDataset.Tab les(0).Columns( 1).ToString
DropDownList1.D ataBind()

when a button is clicked and a postback is caused the button handler
retrieves the cache dataset and rebinds it to a combo box.
I would have thought that if the page was posted back any later than 5
minutes that an error would occur because the cache had expired, but it
doesn't.
The lack of this error indicates to me that the cache is not expiring, but I do not know what I am doing wrong.
How do I make the cache expire in 5 minutes.

cheers

martin

Nov 17 '05 #3
You might also use this syntax.

Cache.Insert ("yourname",you rdatasetvariabl e,New CacheDependency (filepath)
or Nothing ,DateTime.MaxVa lue, TimeSpan.FromMi nutes(5))

I am not sure but I thought the response.cache ... applies to the whole
control or page not the item being named in the cache insert line, but I am
not expert. When I have used the response.cache I usually have several
other lines as follows (but this is for an entire page)

Response.Cache. SetExpires(Date Time.Now.AddSec onds(intCacheTi me))
Response.Cache. SetCacheability (HttpCacheabili ty.Public)
Response.Cache. SetValidUntilEx pires(True)
Response.Cache. VaryByParams("_ p") = True
Response.Cache. VaryByParams("_ h") = True
Response.Cache. VaryByParams("_ c") = True

"martin" <ma***********@ hotmail.com> wrote in message
news:uA******** ******@tk2msftn gp13.phx.gbl...
Hi,

I am storing a dataset in cache, which is happening fine. I can easily
retrive it at postback from the cache, cast it to a dataset and reuse it.
However I have specified that the cache expire in 5 minutes like so.

If Not IsPostBack Then
BindMyDropDown( )
Else
Response.Write( "<hr>Cache Expires 5 minutes" &
DateTime.Now.Ad dSeconds(300) & "<hr>")
'If the cache had expired I would expect this line to cause an
error -- but it doesn't even if I cause postback after 15 minutes!!!
dsMyDataset = CType(Cache("ds "), DataSet)
Response.Cache. SetExpires(Date Time.Now.AddSec onds(300))
End If

I also set the cache expire in exactly the same way in the BindMyDropDown( ) function.
and place the dataset into the cache like so.

//code here
objConn.Open()
daMyDataAdapter .Fill(dsMyDatas et, "Customers" )
objConn.Close()
Cache.Insert("d s", dsMyDataset)
Response.Write( "<hr>Cache Expires 5 minutes" &
DateTime.Now.Ad dSeconds(300) & "<hr>")
Response.Cache. SetExpires(Date Time.Now.AddSec onds(300))

DropDownList1.D ataSource = dsMyDataset
DropDownList1.D ataValueField =
dsMyDataset.Tab les(0).Columns( 0).ToString
DropDownList1.D ataTextField =
dsMyDataset.Tab les(0).Columns( 1).ToString
DropDownList1.D ataBind()

when a button is clicked and a postback is caused the button handler
retrieves the cache dataset and rebinds it to a combo box.
I would have thought that if the page was posted back any later than 5
minutes that an error would occur because the cache had expired, but it
doesn't.
The lack of this error indicates to me that the cache is not expiring, but I do not know what I am doing wrong.
How do I make the cache expire in 5 minutes.

cheers

martin

Nov 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
4116
by: Stanley | last post by:
has anyone managed to use cache application block in a web application? thanks stanley
0
339
by: martin | last post by:
Hi, I am storing a dataset in cache, which is happening fine. I can easily retrive it at postback from the cache, cast it to a dataset and reuse it. However I have specified that the cache expire in 5 minutes like so. If Not IsPostBack Then BindMyDropDown() Else Response.Write("<hr>Cache Expires 5 minutes" &
2
3315
by: Dicky Cheng | last post by:
Hi, I am using absolute expiration to expire my cache object in Cache API. And I set it to expire after 60min. Then I test it, it cache, and everything fine. Then I stop working and lock computer (pc still running), then leave office. Second day I come to the office and unlock computer, the cache still doesn't expire! (It already exceed 60min). And I use the cache, and it still working. And after awhile, the cache start flushing. So I am...
1
1504
by: Tony Hsieh | last post by:
Hi, So I have a asp page that displays the results of a database query that takes 3 minutes to run. I want to cache this dataset for 10 hours so I don't have to perform the 3 minute query every time someone goes to the page. The code I use is: if (Cache == null) { mainConnection = new SqlConnection(@"SERVER=X;DATABASE=Y;Trusted_Connection=Yes");
4
2186
by: SMG | last post by:
Hi there, I want to update my cached dataset, if there is any change in database. I know this is possible in case of ASP.Net 2.0 , But how do I execute the same task with ASP.Net 1.0 As there is need, if any change in database/tables happens then my dataset should be updated. Any help on this,
5
1731
by: Darrel | last post by:
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
3
1546
by: Jon | last post by:
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...
11
12106
by: EagleRed | last post by:
I am writing an ASP.NET 2.0 application that uses master pages. I have some pages that must not be cached on the client. In ASP.NET 1.1 I achieved this using metatags: <meta http-equiv="Expires" content="0"> <meta http-equiv="Pragma" content="no-cache"> <meta http-equiv="Cache-Control" content="no-cache"> This tags are part of the <headelement. Sample code that I have seen shows how to add metatags of the form:
4
4753
by: fnustle | last post by:
Asp.net cache expiration isn't working on the host that I've just moved to. The cache just doesn't expire. It's not the code because it works fine on my localhost and at my previous hosting provider. HttpRuntime.Cache.Insert(XmlCacheKey,ds,null,Cache.NoAbsoluteExpiration, TimeSpan.FromMinutes(1),CacheItemPriority.Normal,saveData) I'm using it as a write-back cache that saves the in-memory dataset to disk every minute if dirty and also...
0
8009
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8432
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8078
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8299
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6753
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5456
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3964
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2442
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1548
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.