Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 488
Junior Mayhé Avatar asked Sep 08 '11 12:09

Junior Mayhé


People also ask

Why Memcached is better than Redis?

Redis uses a single core and shows better performance than Memcached in storing small datasets when measured in terms of cores. Memcached implements a multi-threaded architecture by utilizing multiple cores. Therefore, for storing larger datasets, Memcached can perform better than Redis.

What is the difference between Memcached and Redis?

Although they are both easy to use and offer high performance, there are important differences to consider when choosing an engine. Memcached is designed for simplicity while Redis offers a rich set of features that make it effective for a wide range of use cases.

What are the some important features of Memcached?

Memcached can serve cached items in less than a millisecond, and enables you to easily and cost effectively scale for higher loads. Memcached is popular for database query results caching, session caching, web page caching, API caching, and caching of objects such as images, files, and metadata.

What is the difference between Memcache and Memcached?

They both have very basic difference while storing value. Memcache mostly considers every value as string whereas Memcached stores it value's original type. Thumbs up for your answer !


2 Answers

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.
like image 115
Justin Avatar answered Oct 20 '22 15:10

Justin


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.

like image 43
CodingWithSpike Avatar answered Oct 20 '22 15:10

CodingWithSpike