Я думаю, что это будет работать для вас.Затем, когда вы будете готовы обновить элемент, вы удалите его из кэша вручную и установите его снова ...
Page.Cache.Add("object",
"something",
null,
System.Web.Caching.Cache.NoAbsoluteExpiration,
System.Web.Caching.Cache.NoSlidingExpiration,
CacheItemPriority.NotRemovable,
new CacheItemRemovedCallback((s, o, r) =>
{
// some callback code if you want...
}));
ОБНОВЛЕНО (лучше демо):
private int _counter = 0;
protected void Page_Load(object sender, EventArgs e)
{
// You can add the cache key like this
AddToCache("key", () => "some object " + _counter++);
//Any time you want to refresh the value, you can call RefreshCachedValue
RefreshCachedValue("key");
RefreshCachedValue("key");
RefreshCachedValue("key");
RefreshCachedValue("key");
RefreshCachedValue("key");
// In this demo, the cached value is now "some object 5"
}
private void AddToCache(string key, Func<object> getValueFunction)
{
Page.Cache.Add(key,
getValueFunction(),
null,
System.Web.Caching.Cache.NoAbsoluteExpiration,
System.Web.Caching.Cache.NoSlidingExpiration,
CacheItemPriority.NotRemovable,
new CacheItemRemovedCallback((s, o, r) =>
{
AddToCache(s, getValueFunction);
}));
}
private void RefreshCachedValue(string key)
{
Page.Cache.Remove(key);
}