is there a way to share in-memory caching between two .Net Core Web APIs

biprism 51 Reputation points
2022-09-11T17:37:43.61+00:00

My application right now needs to cache small amount of referenced data, but various data.
Thinking of using in-memory Cache instead of REDIS or NCache. I hope this is a good decision.

If I go with in-memory Cache and implement it, is it possible to share the cache between two APIs?

For example,
First Core Web API, say CacheService uses in-memory cache to get the data cached. this Cache service is called very much at the beginning of the start of the application.
As users go through the application and request various type of data using other services say AP#1, API #2, I want these services rather than going to the database source they access the cache created by the Cacheservice at the beginning and get the data.

Or do I have to implement IMemoryCache in each of the APIs (API#1, API#2, etc)?

Developer technologies | .NET | Blazor
{count} votes

1 answer

Sort by: Most helpful
  1. Bruce (SqlWork.com) 79,101 Reputation points Volunteer Moderator
    2025-08-02T17:04:14.4066667+00:00

    If the apis are the same webapi project, then they can share an in memory cache. If two sites then no. Also if a webfarm, each server will have its own cache.

    To share cache between 2 websites, one site would have the cache, and the other would call an api to check the cache on the first. But it’s probably simpler to use a distributed cache.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.