1

I want to use a memory cache in asp.net core and I'm implementing cache as a Singleton service, now I see IMemoryCache builtin asp.net core.

Do I want to know what is the benefits of IMemoryCache asp.net core against my Singleton service?

Thanks for taking the time and share your ideas

2
  • And to add to the answer, as with any popular library, IMemoryCache is tried and tested by 1000s of developers and will be supported in the future. I'm not so sure about your singleton. Commented Dec 19, 2018 at 17:36
  • @StuartLC Of course, your right. I want to be sure to change my codes. Commented Dec 20, 2018 at 18:59

1 Answer 1

4
  1. You dont need to handle synchronization of threads
  2. SetSlidingExpiration is build in memory cache
  3. RegisterPostEvictionCallback - callback if data are expired.
  4. Limit size of cache
  5. Testing, its much easier to inject and mock data then test with singleton.

You can read all here :)

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, The only thing that came to my mind was services for testing.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.