Я хочу, чтобы иметь возможность передать мою фактическую функцию синтаксического анализа в моем обратном вызове обновления кэша. Как я могу оптимизировать дублирование кода ниже, используя делегатов? СпасибоДелегат для Cache.Insert
//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?
^^^^^^^^^^^^^^^^^^^^^^^^^^
}
Итак, в чем собственно проблема? –
Также см. «[Переполнение стека не допускает теги в заголовках] (http://meta.stackexchange.com/a/130208)». –
thx. Я обновил вопрос. – River