user220201
user220201

Reputation: 4534

memcached use cases

What are some usecases that will benefit from using memcached with a mysql DB. I would guess it would be good for data that does not change much over time.

More specifically if my data changes often then its not worth using memcached right?

Even more specifically I am trying to use the DB as a data structure for a multi player game. So the records are going to change with every move the players make. And all players views should be updated with the latest moves. So my app is getting read and write intensive. Trying to see what I can do about it. If I use memcached, for every write we read 3 times max since 4 players max can play the game at a time.

Thanks.

Pav

Upvotes: 2

Views: 4003

Answers (3)

Nanne
Nanne

Reputation: 64429

Usecase: webshop with a lot of products. These products are assigned to various pages, and per product a user gets to see certain specs. The specs are called with a "getSpec" function. This is expensive and a query per time.

If we put these in memcached, its much quicker. Everytime someone changes something about the product, you jsut update the memcached.

so if your data changes it still can be worth it! Not everything might change at once.

edit: In your case, you could make your write also update memcached: no stale cache. But that's just a random thought, I don't know if making your write heavier like that has any disadvantaged. This would essentially mean you're running everything from memcached, and are just using your DB as a sort of backup :)

Upvotes: 2

jasonbar
jasonbar

Reputation: 13461

Caching is a tradeoff between speed and (potentially) stale data. You have to determine if the speed gain is appropriate given your own use cases.

We cache everything that doesn't require real-time data. Some things that are typically cached: Reports, user content, entire pages (though you may consider caching these to disk via some other system), etc..

Our API allows clients to query for huge amounts of data. We use memcached to store that for quick paging on the clients end.

If you plan ahead, you can setup your application to cache most everything and just invalidate parts of the cache as needed (for instance, when some data in your db is updated).

Upvotes: 1

Eric Petroelje
Eric Petroelje

Reputation: 60539

It's going to depend on how often "often" is and how busy your app is. For example, if you have a piece of data that changes hourly, but that data is queried 500 times per hour, it would probably make sense to cache it even though it changes relatively frequently.

Upvotes: 0

Related Questions