ctor
ctor

Reputation: 875

Store data for a limited time: memcache vs mysql

I need to store some data for a limited amount of time (24 hours at max) which may or may not be accessed in that time. I can use both memcache and mysql for this-

  1. Memcache : Set a key in memcache with expiry time. This will be non-persistent but I can work with that. Access to data will be faster.

  2. MySql : Create a table to store this data and maintain a job to keep archiving this after expiry time. It will be slower comparatively.

Which one should I use? Is this a valid usecase of memcache? (as memcache is used to store data which is accessed very frequently)

Please suggest if any other option is available to store this type of temporary data.

Upvotes: 1

Views: 318

Answers (1)

pratikvasa
pratikvasa

Reputation: 2045

I think memcache will not be very reliable for your case. Memcache is a cache and a cache may evict an object if it starts getting full, plus you won't know that the object is deleted. So if the object is not present you cannot be sure whether it is not there because of eviction or because you actually did not put it there.

Also if you are heavily using memcache and the utilization of memcache is about 75% (which means your memcache is full) then I would suggest not to use memcache. As with very high probability the data will get evicted fast as it is not used. If even this is not an issue for you then you can use memcache.

You can store the this data in mysql. It is a good option.

The other option you could try is mongodb or some other database where you get an option of ttl (time to live). The advantage would be that you can be sure that there was no eviction before the ttl.

Upvotes: 1

Related Questions