473,569 Members | 2,793 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 2840
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
4114
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
3314
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...
1
1502
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...
4
2185
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
1729
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...
11
12098
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...
4
4749
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...
0
7695
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...
0
7922
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. ...
0
8119
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7964
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...
1
5509
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5218
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...
1
2111
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
1209
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
936
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.