Cache not expiring!

G

Guest

I've come across a weird behaviour with regards to the cache object.
I couldn't find any documentation which could explain this.

Basically the problem has to do with the cache item NOT expiring.
If you look at the below code, u'll see that i'm creating 2 cache items with
the keys ONE and TWO.
And both are set to expire in 30 seconds.

When i click the button every time before 30 seconds, i can view the cache
data.
How ever after 30 seconds elapse or after 2 hours, ONLY cache item TWO has
expired.
As for the first item (Key = ONE), it still EXISTS!!!

Is this a bug or have i missed out something?

Code:-

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
If Not IsPostBack Then
Cache.Insert("ONE", "Item One", Nothing, Date.Now.AddSeconds(3), Nothing)
Cache("ONE") = "Item One-1"


Cache.Insert("TWO", "Item Two", Nothing, Date.Now.AddSeconds(3), Nothing)
End If
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
If Cache("ONE") Is Nothing Then
TextBox1.Text = "No cache item"
Else
TextBox1.Text = Cache("ONE")
End If

If Cache("TWO") Is Nothing Then
TextBox2.Text = "No cache item"
Else
TextBox2.Text = Cache("TWO")
End If
End Sub
 
H

Hans Kesting

I've come across a weird behaviour with regards to the cache object.
I couldn't find any documentation which could explain this.

Basically the problem has to do with the cache item NOT expiring.
If you look at the below code, u'll see that i'm creating 2 cache items with
the keys ONE and TWO.
And both are set to expire in 30 seconds.

When i click the button every time before 30 seconds, i can view the cache
data.
How ever after 30 seconds elapse or after 2 hours, ONLY cache item TWO has
expired.
As for the first item (Key = ONE), it still EXISTS!!!

Is this a bug or have i missed out something?

Code:-

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
If Not IsPostBack Then
Cache.Insert("ONE", "Item One", Nothing, Date.Now.AddSeconds(3), Nothing)
Cache("ONE") = "Item One-1"

Cache.Insert("TWO", "Item Two", Nothing, Date.Now.AddSeconds(3), Nothing)
End If
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
If Cache("ONE") Is Nothing Then
TextBox1.Text = "No cache item"
Else
TextBox1.Text = Cache("ONE")
End If

If Cache("TWO") Is Nothing Then
TextBox2.Text = "No cache item"
Else
TextBox2.Text = Cache("TWO")
End If
End Sub

My guess is that when you do
Cache("ONE") = "Item One-1"
you are replacing the previously "inserted" cache-item with one without
restrictions, instead of changing the stored value but keeping the
expiry-settings.

Hans Kesting
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,563
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top