public string Read() { Status = CacheTextFileReaderStatus.FileNotFound; InitContext(); ObjectCache cache = MemoryCache.Default; string fileContents = cache[Context.CacheKey] as string; if (fileContents == null) { if (File.Exists(Context.AbsoluteFilePath)) { CacheItemPolicy policy = CreateCachePolicy(); fileContents = ReadFromFile(); cache.Set(Context.CacheKey, fileContents, policy); Status = CacheTextFileReaderStatus.FileFromStorage; } } else { Status = CacheTextFileReaderStatus.FileFromCache; } return(fileContents); }
private void RenderUI(String fileContent, CacheTextFileReaderStatus status) { if (!String.IsNullOrEmpty(fileContent)) { txtLog.Text = fileContent; Label1.Text = (status == CacheTextFileReaderStatus.FileFromCache) ? "Loaded from cache" : "Loaded from storage"; Label1.Text = Label1.Text + " " + DateTime.Now; } }