Should I create a new CacheItemPolicy for each item that I add to System.Runtime.Caching.ObjectCache?

If by default I want to create a cache where everything expires at 5 am, will I need to create a new CacheItemPolicy for each item that I cache, or could I create a default 5 am CacheItemPolicy and reuse it?

+7
c # caching
source share
2 answers

If you are using AbsoluteExpiration , you need to create a new one for each item. if you use SlidingExpiration , then there may be a fairly strong amount of time.

0
source share

If you want each item to expire individually, yes, you must create a policy for each item.

If you want to expire all elements at once, you can create a Policy for each element using the change monitor for another element in the cache. And as soon as you delete this other element, all elements that control this element will also be deleted.

0
source share

All Articles