fredzvt
fredzvt

Reputation: 331

Using .NET, how and why to use the memcached?

I hear much talk about memcached, but when briefly studied on it, I couldn't understand what advantages I can take instead of using the good old Dictionary<string, object> to cache my data in my applications.

Can someone explain it to me?

Upvotes: 2

Views: 357

Answers (3)

Brian Lyttle
Brian Lyttle

Reputation: 14579

It's not that much different from a Dictionary, it just runs on a different server.

You would want to use memcached if you have need your cache to live beyond the lifetime of your ASP.NET application (which could be recycled at any point). Depending on the size and number of items which you need to cache, you can get to the point where there is not enough space on the IIS server. Remember that it has to run the application and cache all of the items.

In some cases creating a cache of items is very expensive for an application. In these applications you will cause significant pain on other services such as a database if IIS needs to be recycled.

When you start to use memcached you need to make considerations for how it will fit with how you use your database (or other backing store). You need to decide whether you are going to only write to memcached and have that event update the content in the database. From an economic standpoint you should probably be thinking about whether you can use memcached to avoid the cost of installing another database server (assuming that costs more to build/maintain in your situation).

Upvotes: 0

Chris
Chris

Reputation: 4080

The reason I started looking into it was because our app was load-balanced across multiple servers: if I used memcached, I could use its cache (and some implementations seem to have a session state provider as well) to not only split loads across all servers, but also knock one off the farm for maintenance or deployment while keeping the others intact.

Upvotes: 1

Andrey
Andrey

Reputation: 60115

As I understood after reading wikipedia and memcached.org it has at least following features

  • memcached acts like a service to your program, so if your program crash, memcached doesn't
  • it can be distributed amount servers (scalability!)
  • it is cache not just dictionary, so it can delete data if it likes to (no overflow)

similiar concept is not Dictionary<string, object> but HttpContext.Current.Cache, but still it is different

Upvotes: 1

Related Questions