473,386 Members | 1,973 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,386 software developers and data experts.

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.AddSeconds(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(DateTime.Now.AddSeconds( 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(dsMyDataset, "Customers")
objConn.Close()
Cache.Insert("ds", dsMyDataset)
Response.Write("<hr>Cache Expires 5 minutes" &
DateTime.Now.AddSeconds(300) & "<hr>")
Response.Cache.SetExpires(DateTime.Now.AddSeconds( 300))

DropDownList1.DataSource = dsMyDataset
DropDownList1.DataValueField =
dsMyDataset.Tables(0).Columns(0).ToString
DropDownList1.DataTextField =
dsMyDataset.Tables(0).Columns(1).ToString
DropDownList1.DataBind()

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 2813
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**************@tk2msftngp13.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.AddSeconds(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(DateTime.Now.AddSeconds( 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(dsMyDataset, "Customers")
objConn.Close()
Cache.Insert("ds", dsMyDataset)
Response.Write("<hr>Cache Expires 5 minutes" &
DateTime.Now.AddSeconds(300) & "<hr>")
Response.Cache.SetExpires(DateTime.Now.AddSeconds( 300))

DropDownList1.DataSource = dsMyDataset
DropDownList1.DataValueField =
dsMyDataset.Tables(0).Columns(0).ToString
DropDownList1.DataTextField =
dsMyDataset.Tables(0).Columns(1).ToString
DropDownList1.DataBind()

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 strCacheContents as String
dim objItem as DictionaryEntry
dim strName as String
For Each objItem In Cache
strName = objItem.Key.tostring()
strCacheContents = "key=" & strName & "<br />"
Response.Write(strCacheContents)
strCacheContents = "value=" & Convert.ToString(objItem.Value) & "<br/>"
Response.Write(strCacheContents)

Next
"martin" <ma***********@hotmail.com> wrote in message
news:uA**************@tk2msftngp13.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.AddSeconds(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(DateTime.Now.AddSeconds( 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(dsMyDataset, "Customers")
objConn.Close()
Cache.Insert("ds", dsMyDataset)
Response.Write("<hr>Cache Expires 5 minutes" &
DateTime.Now.AddSeconds(300) & "<hr>")
Response.Cache.SetExpires(DateTime.Now.AddSeconds( 300))

DropDownList1.DataSource = dsMyDataset
DropDownList1.DataValueField =
dsMyDataset.Tables(0).Columns(0).ToString
DropDownList1.DataTextField =
dsMyDataset.Tables(0).Columns(1).ToString
DropDownList1.DataBind()

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",yourdatasetvariable,New CacheDependency(filepath)
or Nothing ,DateTime.MaxValue, TimeSpan.FromMinutes(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(DateTime.Now.AddSeconds( intCacheTime))
Response.Cache.SetCacheability(HttpCacheability.Pu blic)
Response.Cache.SetValidUntilExpires(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**************@tk2msftngp13.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.AddSeconds(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(DateTime.Now.AddSeconds( 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(dsMyDataset, "Customers")
objConn.Close()
Cache.Insert("ds", dsMyDataset)
Response.Write("<hr>Cache Expires 5 minutes" &
DateTime.Now.AddSeconds(300) & "<hr>")
Response.Cache.SetExpires(DateTime.Now.AddSeconds( 300))

DropDownList1.DataSource = dsMyDataset
DropDownList1.DataValueField =
dsMyDataset.Tables(0).Columns(0).ToString
DropDownList1.DataTextField =
dsMyDataset.Tables(0).Columns(1).ToString
DropDownList1.DataBind()

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
by: Stanley | last post by:
has anyone managed to use cache application block in a web application? thanks stanley
0
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...
2
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...
1
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...
4
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...
5
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...
3
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...
11
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...
4
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...

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.