自动重新填充在到期时间的缓存 [英] Automatically re-populate the cache at expiry time

查看:239
本文介绍了自动重新填充在到期时间的缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前,我缓存的方法调用的结果。

I currently cache the result of a method invocation.

的缓存code遵循标准模式:它使用的项目在缓存中,如果它存在,否则它计算的结果,在返回之前缓存以备日后调用

The caching code follows the standard pattern: it uses the item in the cache if it exists, otherwise it calculates the result, caching it for future calls before returning it.

我想从高速缓存未命中屏蔽客户端code(例如,当项目已过期)。

I would like to shield client code from cache misses (e.g. when the item has expired).

我想产卵一个线程等待缓存对象的生命周期中,以然后运行提供的函数,重新填充缓存时(或之前)现有项目到期。

I am thinking of spawning a thread to wait for the lifetime of the cached object, to then run a supplied function to repopulate the cache when (or just before) the existing item expires.

任何人都可以分享与此相关的经验吗?这听起来像一个明智的做法?

Can anyone share any experience related to this? Does this sound like a sensible approach?

我使用.NET 4.0。

I'm using .NET 4.0.

推荐答案

由于这是ASP.NET中,的 Cache.Insert() 方法允许你指定一个回调委托。

Since this is ASP.NET, the Cache.Insert() method allows you to specify a callback delegate.

这听起来像一个明智的做法?

Does this sound like a sensible approach?

是的,回调(和文件依赖性)提供的正是这种情况。你还有RO使资源,延迟和乱最新性之间找到一个平衡。

Yes, the callback (and File-dependency) are supplied for exactly this kind of situation. You still have ro make a trade of between resources, latency and out-of-dateness.

这篇关于自动重新填充在到期时间的缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆