Cache not expiring!

Discussion in 'ASP .Net' started by Guest, Aug 3, 2006.

  1. Guest

    Guest 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
     
    Guest, Aug 3, 2006
    #1
    1. Advertisements

  2. Guest

    Guest Guest

    The above query relates to ASP.NET 1.1
     
    Guest, Aug 3, 2006
    #2
    1. Advertisements

  3. Guest

    Hans Kesting Guest

    I've come across a weird behaviour with regards to the cache object.
    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
     
    Hans Kesting, Aug 3, 2006
    #3
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.