private IValueDescriptor <Entry> WrapValueDescriptor(IValueDescriptor <V> evictableValueDescriptor)
 {
     return(new ValueDescriptorImpl <Entry>(
                entry =>
     {
         return entry.ValueRef.Valid ?
         evictableValueDescriptor.GetSizeInBytes(entry.ValueRef.Get()) : 0;
     }));
 }
 /// <summary>
 /// Checks the cache constraints to determine whether the new value
 /// can be cached or not.
 /// </summary>
 private bool CanCacheNewValue(V value)
 {
     lock (_cacheGate)
     {
         int newValueSize = _valueDescriptor.GetSizeInBytes(value);
         return((newValueSize <= _memoryCacheParams.MaxCacheEntrySize) &&
                (InUseCount <= _memoryCacheParams.MaxCacheEntries - 1) &&
                (InUseSizeInBytes <= _memoryCacheParams.MaxCacheSize - newValueSize));
     }
 }
 private int GetValueSizeInBytes(V value)
 {
     return((value == null) ? 0 : _valueDescriptor.GetSizeInBytes(value));
 }