public void Clear() { cache.Clear(); CacheChangedEvent?.Invoke(this, new EntityCacheChangedEventArgs() { IsClear = true }); }
public void Delete(string id) { if (cache.ContainsKey(id)) { bool removed; do { removed = cache.TryRemove(id, out TEntity entity); } while (!removed); CacheChangedEvent?.Invoke(this, new EntityCacheChangedEventArgs() { Id = id, IsDeleted = true }); } }
public void AddOrSet(TEntity entity) { if (entity == null) { return; } cache.AddOrUpdate(entity.Id, s => entity, (s, e) => entity); RemoveIfReachedMax(); CacheChangedEvent?.Invoke(this, new EntityCacheChangedEventArgs() { Id = entity.Id, IsAltered = true }); }