ObjectCache не обновляется после вызова функции обратного вызова
Контекст: мне нужен класс, чтобы поместить несколько ключевых слов в кеш из текстового файла. Я поместил прослушиватель в этот файл, чтобы при его изменении обновлялся сам кэш.
ASP.NET MVC 3 - Framework 4.5
Global.asax:
protected void Application_Start()
{
// Caching keywords
BigBrother.InitiateCaching(BigBrother.ReInitiateCaching);
}
Класс BigBrother.cs:
private static readonly Cache _cacheHandler = new Cache();
public static void InitiateCaching(CacheEntryRemovedCallback pCallBackFunction)
{
string filePath = HostingEnvironment.MapPath("~/Configurations/Surveillance/keywords.txt");
var fileContent = File.ReadAllText(filePath, Encoding.UTF8).Split(';');
_cacheHandler.AddToMyCache("surveillanceKeywords", fileContent, CachePriority.Default, new List<string> { filePath }, pCallBackFunction);
}
public static void ReInitiateCaching(CacheEntryRemovedArguments arguments)
{
InitiateCaching(ReInitiateCaching);
}
Cache.cs:
public void AddToMyCache(string cacheKeyName, object cacheItem, CachePriority cacheItemPriority, List<string> filePath,
CacheEntryRemovedCallback pCallBackFunction)
{
callback = pCallBackFunction;
policy = new CacheItemPolicy
{
Priority = (cacheItemPriority == CachePriority.Default) ? CacheItemPriority.Default : CacheItemPriority.NotRemovable,
AbsoluteExpiration = DateTimeOffset.Now.AddYears(1),
RemovedCallback = callback
};
policy.ChangeMonitors.Add(new HostFileChangeMonitor(filePath));
cache.Set(cacheKeyName, cacheItem, policy);
}
Таким образом, общий рабочий процесс выглядит следующим образом:1. Application_Start запускается, и BigBrother помещает ключевые слова в кэш с помощью функции обратного вызова (работает очень хорошо) 2. Прослушивает файл "Keywords.txt" 3. Когда файл "Keywords.txt" редактируется, обновить кэш (на самом деле, ReInitiateCaching вызывается, но мой элемент кэша "illanceKeywords"возвращает ноль)
Все это работает в моей локальной среде, но не работает на сервере. Я что-то пропустил?
Спасибо.