/// <summary> /// Adds/Updates the data from in reposiotry and tells all (subscribing) clients about it. /// /// Override to implement custom logic /// </summary> /// <param name="model"></param> public virtual void Update(TV model) { var command = DataSyncCommand.Update; if (model.Id == Guid.Empty) { model.Id = Guid.NewGuid(); command = DataSyncCommand.Add; } model = _store.AddOrUpdate(model.Id, model); Sync(command, model); }
private async Task <CacheEntry <TValue> > LoadAndCacheEntryAsync(TKey key, Func <TKey, Task <TValue> > loaderFunction) { if (loaderFunction == null) { throw new ArgumentNullException(nameof(loaderFunction)); } var stopwatch = System.Diagnostics.Stopwatch.StartNew(); CacheEntry <TValue> entry = new CacheEntry <TValue>(); entry.CachedValue = await loaderFunction(key).ConfigureAwait(false); entry.TimeLoaded = DateTime.UtcNow;; _kvStore.AddOrUpdate(key, entry, (k, v) => entry); stopwatch.Stop(); TryMissedCallback(key, entry, stopwatch.ElapsedMilliseconds); return(entry); }
public void AddData <T>(string key, T item) { _data.AddOrUpdate(key, item); }