public static SmartCache CreateCache(string name, Func <string, object> f, TimeSpan refresh, TimeSpan clear) { lock (Caches) { if (!Caches.ContainsKey(name)) { var cache = new SmartCache(f, refresh, clear); Caches.Add(name, cache); } else { var cache = Caches[name]; if (cache.RefreshTime != refresh) { cache.RefreshTime = refresh; } if (cache.ClearTime != clear) { cache.ClearTime = clear; } } } return(Caches[name]); }
private async void LoadCaches(DataFilter filter) { Caches.Clear(); IEnumerator <DomainModel.Cache> e = cacheManager.GetFilteredCacheList(filter).GetEnumerator(); while (await Task.Factory.StartNew(() => e.MoveNext())) { Caches.Add(new CacheVM(cacheManager, e.Current)); } }
public int SaveIntoCaches() { if (Caches.Find(delegate(MODEL dele) { return(dele.Id.ToInt32() == this.Id.ToInt32()); }) == null) { Caches.Add(this); return(1); } else { return(0); } }
public long Set(string utterance, HttpResponseMessage message) { var cache = new CachedLuisCache(utterance, message); Caches.Add(cache); var size = cache.Size; TotalBytes += size; Bytes += size; TotalCaches += 1; return(Bytes); }
public bool Set(string key, IActionResult data, int expireTime = -1) { if (Caches.ContainsKey(key)) { Caches[key] = data; } else { Caches.Add(key, data); } return(true); }
/// <summary> /// Initializes a new instance of the <see cref="Cache"/> class. /// </summary> /// <param name="caches">The caches.</param> /// <exception cref="ArgumentException"> /// No caches were found in the system. Please register one prior to initializing. /// </exception> public Cache(IEnumerable <ICache> caches) { caches ??= Array.Empty <ICache>(); if (!caches.Any()) { throw new ArgumentException("No caches were found in the system. Please register one prior to initializing."); } var CacheAssembly = typeof(Cache).Assembly; Caches = caches.Where(x => x.GetType().Assembly != CacheAssembly).ToDictionary(x => GetKey(x.Name)); var DefaultKey = GetKey("Default"); if (!Caches.TryGetValue(DefaultKey, out var TempCache)) { Caches.Add(DefaultKey, caches.First().Clone()); } }
/// <summary> /// Creates the discovery cache. /// </summary> /// <returns>DiscoCache.</returns> public static DiscoCache CreateDiscoCache(string ecoSpaceUrl = null) { if (String.IsNullOrWhiteSpace(ecoSpaceUrl)) { ecoSpaceUrl = ConfigurationHelper.DiscoEndpoint; } if (Caches.ContainsKey(ecoSpaceUrl)) { return(Caches[ecoSpaceUrl]); } var c = new DiscoCache() { EcoSpaceUrl = ecoSpaceUrl }; Caches.Add(ecoSpaceUrl, c); return(c); }
public HttpResponseMessage Get(string utterance) { // We always add used TotalUsed++; Used++; var input = new CachedLuisCache(utterance, null); // TODO: make it first if (Caches.Remove(input, out CachedLuisCache output)) { Caches.Add(output); return(output.GetMessage()); } else { return(null); } }