Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/299.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python中的缓存密钥过期事件或回调_Python_Caching - Fatal编程技术网

Python中的缓存密钥过期事件或回调

Python中的缓存密钥过期事件或回调,python,caching,Python,Caching,我试图找到一种方法,当python中的缓存项过期时,接收对用户函数的调用 此功能已存在于.NET中,如下所示: string test = "test1"; Cache.Insert("Key", test, dependancy, DateTime.Now.AddMinutes(DateTime.Now), System.Web.Caching.Cache.NoSlidingExpiration, CacheItemPriority.High,

我试图找到一种方法,当python中的缓存项过期时,接收对用户函数的调用

此功能已存在于.NET中,如下所示:

string test = "test1";
Cache.Insert("Key", 
    test, 
    dependancy, 
    DateTime.Now.AddMinutes(DateTime.Now), 
    System.Web.Caching.Cache.NoSlidingExpiration, 
    CacheItemPriority.High, 
    new CacheItemRemovedCallback(CacheRemovedCallback));

public string CacheRemovedCallback(String key, object value, System.Web.Caching.CacheItemRemovedReason removedReason)
{
    //Do something here
    return  = "Cache Expired for : " + key;
}

非常感谢您的任何建议。

您使用的是特定的缓存库还是即将选择的缓存库?@Leon我目前没有任何选择。任何东西都是健壮的、可用于生产的,并且具有基本的数据缓存功能以及密钥过期事件。@muntakim360,您找到解决方案了吗?我知道三年前有人问过这个问题,但现在仍然是:)你在使用任何特定的缓存库还是准备选择一个?@Leon我现在没有任何选择。任何东西都是健壮的、可用于生产的,并且具有基本的数据缓存功能以及密钥过期事件。@muntakim360,您找到解决方案了吗?我知道这个问题是3年前提出的,但仍然是:)