locked
MemoryCache - UpdateCallback is not called RRS feed

  • Question

  • Dear all,

    I've the following example and I don't know why but the "UpdateCallback" is not called if I remove the cached item. In the documentation I read that it should be called when the cache is removing the item. What did I wrong?

    Heres the example:

    Imports System.Runtime.Caching
    
    Public Class Form1
    
      Public Sub New()
    
        ' Dieser Aufruf ist für den Designer erforderlich.
        InitializeComponent()
    
        ' Fügen Sie Initialisierungen nach dem InitializeComponent()-Aufruf hinzu.
        Dim objItem As New CacheItem("1", "Value")
    
        Dim objPolicy As New CacheItemPolicy()
        objPolicy.SlidingExpiration = New TimeSpan(1, 0, 0)
        objPolicy.UpdateCallback = New CacheEntryUpdateCallback(AddressOf CacheEntryUpdateCallback)
        'objPolicy.RemovedCallback = New CacheEntryRemovedCallback(AddressOf CacheEntryRemovedCallback)
    
        MemoryCache.Default.Set(objItem, objPolicy)
    
      End Sub
    
      Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        MemoryCache.Default.Remove("1")
      End Sub
    
      Private Sub CacheEntryUpdateCallback(arguments As System.Runtime.Caching.CacheEntryUpdateArguments)
        Debug.WriteLine("CacheEntryUpdateCallback Called")
      End Sub
    
      Private Sub CacheEntryRemovedCallback(arguments As System.Runtime.Caching.CacheEntryRemovedArguments)
        Debug.WriteLine("CacheEntryRemovedCallback Called")
      End Sub
    
    End Class
    

    Kind regards


    Rainer

    Friday, January 22, 2016 4:07 PM

Answers

  • Seems that currently UpdateCallback is called only in case of expiration. Perhaps it is a limitation, defect, or incomplete documentation. Use RemovedCallback instead.

    • Marked as answer by RaBu78 Monday, January 25, 2016 6:41 AM
    Friday, January 22, 2016 5:33 PM