Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c#

.net

caching

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

like image 249
Daryl Avatar asked Mar 11 '15 15:03

Daryl


People also ask

Is .NET Memorycache thread safe?

The AddOrGetExisting method from the . NET Framework is thread-safe (according to the documentation).

How do I initialize memory cache?

Refer to the following example to see how to initialize the cacheItemPolicy class and add a time value to store the data in the cache. var cacheItemPolicy = new CacheItemPolicy { AbsoluteExpiration = DateTimeOffset. Now. AddSeconds(120.0) }; var result = cache.

What is a runtime cache?

Runtime caching refers to gradually adding responses to a cache "as you go". While runtime caching doesn't help with the reliability of the current request, it can help make future requests for the same URL more reliable.


1 Answers

If you are using AbsoluteExpiration then you have to create a new one for every item. if you are using SlidingExpiration then a sinple time span might be enough.

like image 175
aggsol Avatar answered Oct 22 '22 16:10

aggsol