我希望能够在我的缓存更新回调中传递我的实际解析函数。如何使用委托优化下面的代码重复?谢谢
//intial setup code
public void getJSONContent() //can I pass itemUpdateCallback in here? Does it make sense?
{
Content = (String)HttpContext.Current.Cache[Path];
if (Content == null)
{
Content = parseXMLContent();
HttpContext.Current.Cache.Insert(
key,
Content,
new CacheDependency(Path),
Cache.NoAbsoluteExpiration,
Cache.NoSlidingExpiration,
jsonUpdateCallback); //callback in the event of my file in cache has changed
^^^^^^^^^^^^^^^^^^
}
}
private void jsonUpdateCallback(string key, CacheItemUpdateReason reason, out object value, out CacheDependency dependency, out DateTime exipriation, out TimeSpan slidingExpiration)
{
dependency = new CacheDependency(key);
exipriation = Cache.NoAbsoluteExpiration;
slidingExpiration = Cache.NoSlidingExpiration;
value = jsonXMLContent(); //how can pass this function into here, so I can can have different parse functions using the same code?
^^^^^^^^^^^^^^^^^^^^^^^^^^
}
//intial setup code
public void getXMLContent() //can I pass itemUpdateCallback in here? Does it make sense?
{
Content = (String)HttpContext.Current.Cache[Path];
if (Content == null)
{
Content = parseXMLContent();
HttpContext.Current.Cache.Insert(
key,
Content,
new CacheDependency(Path),
Cache.NoAbsoluteExpiration,
Cache.NoSlidingExpiration,
xmlUpdateCallback); //callback in the event of my file in cache has changed
^^^^^^^^^^^^^^^^^^
}
}
private void xmlUpdateCallback(string key, CacheItemUpdateReason reason, out object value, out CacheDependency dependency, out DateTime exipriation, out TimeSpan slidingExpiration)
{
dependency = new CacheDependency(key);
exipriation = Cache.NoAbsoluteExpiration;
slidingExpiration = Cache.NoSlidingExpiration;
value = parseXMLContent(); //how can pass this function into here, so I can can have different parse functions using the same code?
^^^^^^^^^^^^^^^^^^^^^^^^^^
}