コード例 #1
0
 public void Clear()
 {
     cache.Clear();
     CacheChangedEvent?.Invoke(this, new EntityCacheChangedEventArgs()
     {
         IsClear = true
     });
 }
コード例 #2
0
 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
         });
     }
 }
コード例 #3
0
        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
            });
        }