示例#1
0
 public bool EvictData(CacheSpace space, ICacheSpaceConsumer consumer, long requiredSpace)
 {
     if (!consumer.IsEvictionEnabled)
     {
         return(false);
     }
     consumer.EvictData(requiredSpace);
     return(true);
 }
示例#2
0
 public void RemoveConsumer(ICacheSpaceConsumer consumer)
 {
     lock (this)
     {
         if (_consumers.Contains(consumer))
         {
             _consumers.Remove(consumer);
         }
     }
 }
示例#3
0
 public void AddConsumer(ICacheSpaceConsumer consumer)
 {
     lock (this)
     {
         if (!_consumers.Contains(consumer))
         {
             _consumers.Add(consumer);
         }
     }
 }
示例#4
0
 public void Release(ICacheSpaceConsumer consumer, long restoreSize)
 {
     lock (this)
     {
         _currentSize -= restoreSize;
     }
     if (_statsCollector != null)
     {
         _statsCollector.SetStatsValue(StatisticsType.CacheSize, _currentSize);
     }
 }
示例#5
0
 public bool CanConsumeSpace(CacheSpace space, ICacheSpaceConsumer consumer, long requiredSpace)
 {
     if (space.AvaialbeSpace < requiredSpace)
     {
         return(EvictData(space, consumer, requiredSpace));
     }
     return(true);
     // if user thread is supposed to do eviction then there is no need for threshold i guess.
     //if (space.AvaialbeSpace < space.Threshold)
     //{
     //    //TODO: start eviction currently it is need base to user thread will do the eviction.
     //}
 }
示例#6
0
 public void Consume(ICacheSpaceConsumer consumer, long neededSpace)
 {
     lock (this)
     {
         if (IsFull)
         {
             if (!_spacePolicy.EvictData(this, consumer, neededSpace))
             {
                 return;
             }
         }
         if (_spacePolicy.CanConsumeSpace(this, consumer, neededSpace))
         {
             _currentSize += neededSpace;
             if (_statsCollector != null)
             {
                 _statsCollector.SetStatsValue(StatisticsType.CacheSize, _currentSize);
             }
         }
     }
 }
示例#7
0
 public void RemoveConsumer(ICacheSpaceConsumer consumer)
 {
     throw new NotImplementedException();
 }