/// <summary> /// Retrieves the file data content based based on filename: dataKey.txt /// Files must be located same folder as running routine. /// Exceptions - ApplicationException for any issue. /// </summary> /// <param name="dataKey">filename without extension.</param> /// <returns>Text file content.</returns> public virtual DataRetrievalResult GetDataBasedOnKey(string dataKey) { try { DateTime retrievedOn = DateTime.UtcNow; string path = dataKey + ".txt"; string fileContent = System.IO.File.ReadAllText(path); DataRetrievalResult result = new DataRetrievalResult(dataKey, fileContent, retrievedOn); return(result); } catch (Exception ex) { throw new ApplicationException(string.Format("Error reding file for dataKey: {0}", dataKey), ex); } }
void Caching() { ObjectCache cache = MemoryCache.Default; DataRetrievalResult fileContents = cache[result.DataKey] as DataRetrievalResult; if (fileContents == null) { CacheItemPolicy policy = new CacheItemPolicy(); policy.AbsoluteExpiration = DateTimeOffset.Now.AddMinutes(1); List <DataRetrievalResult> filePaths = new List <DataRetrievalResult>(); filePaths.Add(result); cache.Add(result.DataKey, result, policy); } else { result = fileContents; } }
public override DataRetrievalResult GetDataBasedOnKey(string dataKey) { result = base.GetDataBasedOnKey(dataKey); Caching(); return(result); }