キャッシュ更新コールバックで実際の解析関数を渡すことができるようにしたいと考えています。デリゲートを使用して以下のコードの複製を最適化するにはどうすればよいですか? ありがとう
//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?
^^^^^^^^^^^^^^^^^^^^^^^^^^
}