public bool EvictData(CacheSpace space, ICacheSpaceConsumer consumer, long requiredSpace) { if (!consumer.IsEvictionEnabled) { return(false); } consumer.EvictData(requiredSpace); return(true); }
public void RemoveConsumer(ICacheSpaceConsumer consumer) { lock (this) { if (_consumers.Contains(consumer)) { _consumers.Remove(consumer); } } }
public void AddConsumer(ICacheSpaceConsumer consumer) { lock (this) { if (!_consumers.Contains(consumer)) { _consumers.Add(consumer); } } }
public void Release(ICacheSpaceConsumer consumer, long restoreSize) { lock (this) { _currentSize -= restoreSize; } if (_statsCollector != null) { _statsCollector.SetStatsValue(StatisticsType.CacheSize, _currentSize); } }
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. //} }
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); } } } }
public void RemoveConsumer(ICacheSpaceConsumer consumer) { throw new NotImplementedException(); }