简体   繁体   中英

Share cache between 2 web applications

I have 2 web applications A and B, A is used by administrators to manage directories and security roles ...and B is used by other users to ... In the web app B when the user is logged in, we load infomations related to the user in the cache. We have encoutred some issue when the admin update some date using the web app A, these informations are not reflected in the web B because the data is cached in the memory. Is there any way to update share the cache between the apps without creating a new web app or a WCF service ?

Thanks for you help, Bilel

You cannot share the same memory cache between 2 different web apps, because the cache resides in each process' memory.

What you can do instead is use a distributed cache like Redis, that would let you share the cache items between different processes, web apps or even different machines.

If you are on Azure you can easily create a completely managed one in minutes (see here ) and start using it right away.

⚠️ I'd like to give you a warning, though.

When you start using a distributed cache you may be tempted to just use that directly, instead of a memory cache: that would be most probably a mistake, because you will loose data locality and because using distributed systems as if they are local suffer from known problems .

So typically you then decide to use a local memory cache (for each process/server) and a distributed one as a 2nd layer cache, to get the best of both worlds: this is, for example, what Stack Overflow itself does (see here ).

But now you will need to manage all the functionality required to coordinate the synchronized read/update/removal of data between the 2 layers of cache, including edge cases, timeouts, fallbacks, etc.

If I may, I would like to suggest trying FusionCache ⚡🦥 : it is a free, oss, cross-platform cache with a local in-memory layer and an optional distributed one (eg: Redis) all managed transparently for you.

I just released it and it would be great if you find it helpful in some ways.

You may also find some of the other features interesting, like an optimization to avoid multiple concurrent factory calls at the same time for the same cache key, a fail-safe mechanism, advanced timeouts with background factory completion and support for an optional, distributed 2nd level .

If you will give it a chance please let me know what you think.

/shameless-plug

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM