开发者

What are the advantages of Memcached compared to .NET Cache system?

开发者 https://www.devze.com 2023-04-03 07:29 出处:网络
I saw some people in a development team using Memcached to cache database results, instead of built-in .NET Framework Cache system. I do not understand clearly why would they use this specific cache.

I saw some people in a development team using Memcached to cache database results, instead of built-in .NET Framework Cache system. I do not understand clearly why would they use this specific cache.

Maybe the performance is better.

Anyway, is there any real advantages of using Memcached (and not native .NET Cache)开发者_如何学Python?


Memcached is distributed - crucially this means that if I have a cluster of servers accessing the cache, all of them are essentially reading from and writing to the same cache. The built in .Net cache does not have this feature (at least I know the ASP.Net one doesn't).

As each machine has its own independent cache this means that (for example):

  • If machine A computes / reads a value and places it in the cache, machine B doesn't get any benefit from this. Each machine needs to independently maintain and fill its own cache. This also potentially wastes space as the same entry may be present in the cache of many different machines.
  • If machine B invalidates a cache entry, machine A won't be aware of this invalidation and may continue to use stale / out of date data

Memcached has neither of those problems - once an entry is placed in the cache all machines in the cluster can retrieve the same cached item. Invalidating an entry in the cache invalidates it for everyone.

Disadvantages

If your application needs to function on a cluster of machines then it is very likely that you will benefit from a distributed cache, however if your application only needs to run on a single machine then you won't gain any benefit from using a distributed cache and will probably be better off using the built-in .Net cache.

  • Accessing a memcached cache requires interprocess / network communication, which will have a small performance penalty over the .Net caches which are in-process.
  • Memcached works as an external process / service, which means that you need to install / run that service in your production environment. Again the .Net caches don't need this step as they are hosted in-process.


A better comparison for Memcached would actually be Azure App Fabric Caching, which was added with .NET 4 and Azure. It is a distributed cluster-able cache solution intended for clustered and cloud computing. However, Memcached has also been around for a long time (2003-ish I think), so is well established, and considered to be the benchmark by which others are judged. Memcached has also been ported to just about every language out there, and can be run on linux or windows servers. Azure Caching is still relatively new, so not many people have really used it yet.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号