locked
Get details of application cache RRS feed

  • Question

  • User1555919309 posted

    Is there a way to get application cache details? For example expiration date time? Last reset date time? below is my cache clear code. I also want to display cache expiration date on the page. (append to listitem.Text = item.Key & ": " & item.Value)

    Is there a (reasonable/simple) way to collect the “oldest age” of the cache and display it next to each cache object? (Basically, to know when for that cache object when it was last reset, or how far back it goes.)

        Private Sub btnClearSpecificCache_Click(sender As Object, e As EventArgs) Handles btnClearSpecificCache.Click
            Dim count As Integer = chkCache.Items.Count
            Dim n As Integer = -1
            For i As Integer = 0 To count - 1
                If chkCache.Items(i).Selected Then
                    Cache.Remove(chkCache.Items(i).Value)
                    message.InnerHtml = message.InnerHtml & chkCache.Items(i).Value & " removed.<br />"
                End If
            Next
        End Sub
        Private Sub ClearCache_Load(sender As Object, e As EventArgs) Handles Me.Load
             If Not IsPostBack Then
                For Each item As DictionaryEntry In Cache
                    Dim listitem As ListItem = New ListItem()
                    listitem.Text = item.Key & ": " & item.Value
                    listitem.Value = item.Key.ToString
                    chkCache.Items.Add(listitem)
                Next 
            End If
        End Sub

    Wednesday, February 24, 2021 7:09 PM

Answers

  • User1535942433 posted

    Hi TimJin,

    As far as I think,you could have a base object (that all your cacheable objects inherits from) with the expiry time as a property that is set at the time you add to cache. When you extract the object, you check for the property and you have the expiration time to calculate the difference.

    When you do an IISReset the IIS cache will be cleared and then will start to be rebuilt after it starts back up as client requests come in. IISReset (although harsh) will clear the IIS cache but it won't do anything with local caches in proxies or clients.

    More details,you could refer to below articles:

    https://stackoverflow.com/questions/6739130/how-to-get-expiry-date-for-cached-item

    https://serverfault.com/questions/176943/will-an-iis-reset-force-cached-items-to-be-resent

    Best regards,

    Yijing Sun

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, February 25, 2021 2:45 AM
  • User475983607 posted

    I wonder if Cache itself has some functionality that shows its expiration time, last reset date, something like this?

    According to the reference documentation I provided above, yhe Cache type does NOT have this feature.  It is up to you to write some code.  Again, I would simply add a property to the item being cached.  

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, February 25, 2021 3:51 AM

All replies

  • User475983607 posted

    TimJin

    Is there a way to get application cache details? For example expiration date time?

    The expiration is an input parameter when an item is added to the cache.  You already have the expiration because you set the expiration.  I would add an expiration field/property to the item you wish to cache that way the value is persisted within the item.

    See the Cache reference documentation.  The docs show all the files, properties, methods, etc...

    https://docs.microsoft.com/en-us/dotnet/api/system.web.caching.cache?view=netframework-4.8

    Wednesday, February 24, 2021 8:57 PM
  • User1555919309 posted

    Thank you mgebhard for your answer.

    I know we can set expiration when adding a cache. My manager asked me to create a page showing expiration time of each cache, and last reset time. I need to consider so many things. For example, application auto recycle can reset the cache, the expiration time when added can reset the cache, manual clear cache resets the cache too. I wonder if Cache itself has some functionality that shows its expiration time, last reset date, something like this?

    Wednesday, February 24, 2021 9:41 PM
  • User1535942433 posted

    Hi TimJin,

    As far as I think,you could have a base object (that all your cacheable objects inherits from) with the expiry time as a property that is set at the time you add to cache. When you extract the object, you check for the property and you have the expiration time to calculate the difference.

    When you do an IISReset the IIS cache will be cleared and then will start to be rebuilt after it starts back up as client requests come in. IISReset (although harsh) will clear the IIS cache but it won't do anything with local caches in proxies or clients.

    More details,you could refer to below articles:

    https://stackoverflow.com/questions/6739130/how-to-get-expiry-date-for-cached-item

    https://serverfault.com/questions/176943/will-an-iis-reset-force-cached-items-to-be-resent

    Best regards,

    Yijing Sun

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, February 25, 2021 2:45 AM
  • User475983607 posted

    I wonder if Cache itself has some functionality that shows its expiration time, last reset date, something like this?

    According to the reference documentation I provided above, yhe Cache type does NOT have this feature.  It is up to you to write some code.  Again, I would simply add a property to the item being cached.  

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, February 25, 2021 3:51 AM
  • User1555919309 posted

    Thank you so much, Yijing Sun. 

    Thursday, February 25, 2021 4:24 AM
  • User1555919309 posted

    Thank you so much, mgebhard.

    Thursday, February 25, 2021 4:25 AM