Saeid Mirzaei
Saeid Mirzaei

Reputation: 1236

Benefit of Asp.net core IMemoryCache

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

Upvotes: 1

Views: 430

Answers (1)

Vova Bilyachat
Vova Bilyachat

Reputation: 19494

  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 :)

Upvotes: 4

Related Questions