System.Runtime.Caching does not free BitmapImage objects

I use the new System.Runtime.Caching library for caching in my application and define it as follows in App.config:

<system.runtime.caching>
    <memoryCache>
        <namedCaches>
            <add name="MyCache" cacheMemoryLimitMegabytes="10"
                 physicalMemoryLimitPercentage="30" pollingInterval="00:00:10" />
        </namedCaches>
    </memoryCache>
</system.runtime.caching>

Then from the code I create it as follows: _cache = new MemoryCache("MyCache");

And add these lines: _cache.Add(resourceName, resource, new CacheItemPolicy());

I use this cache to store objects BitmapImage, and to make sure the cache works correctly, I added ten objects to the cache BitmapImage, each of which has an image of about 7 MB in size. Then I waited ten seconds for the survey to take place, and checked the cache entries, but they were all there. Not a single object was evicted.

- ? , App.config . , BitmapImage ? ?

+5
1

,

new CacheItemPolicy()

: AbsoluteExpiration 31/12/9999 11:59:59 PM +00: 00

10 , 2

CacheItemPolicy item = new CacheItemPolicy();

item.SlidingExpiration = new TimeSpan(0, 10, 0);

item.AbsoluteExpiration = DateTime.Now.AddMinutes(10);

, 10 reset, .

+3

All Articles