public object GetAndPutIfNonExisting(KeyAndItsDependingKeys keyAndItsDependingKeys, CachedMethodInformation cachedMethodInformation, Func <object> originalMethod) { string cacheKey = keyAndItsDependingKeys.Key.Replace("|", "/"); var cacheFile = Path.Combine(this._directory, $"{cacheKey}.json"); if (File.Exists(cacheFile)) { return (JsonConvert.DeserializeObject( File.ReadAllText(cacheFile), cachedMethodInformation.Method.ReturnType)); } else { var valueToCache = originalMethod(); if (!Directory.Exists(Path.GetDirectoryName(cacheFile))) { Directory.CreateDirectory(Path.GetDirectoryName(cacheFile)); } File.WriteAllText(cacheFile, JsonConvert.SerializeObject( valueToCache)); return(valueToCache); } }
public object GetAndPutIfNonExisting(KeyAndItsDependingKeys keyAndItsDependingKeys, MethodInfo method, IEnumerable <object> arguments, Func <object> originalMethod) { var eventInformation = new CachedMethodInformation(method, arguments); return(_cache.GetAndPutIfNonExisting(keyAndItsDependingKeys, eventInformation, originalMethod)); }