Reputation: 1511
I have a web application which would perform well if some database operations are cached. Those are static data's and new data are added everyday. To reduce the database read operation i'll be using memcached.
What will happen if i don't give an expiry time for the data i put in memcached. Will it affect the performance by consuming more RAM..? Is it good to ditch the expiry time while adding data to cache.
PS: We use AWS to deploy the webapp with ngnix, php, mysql.
Upvotes: 1
Views: 2178
Reputation: 150108
Presumably when your app is still running in the year 2050, some things that you put in cache way back in 2012 will no longer be relevant. If you don't provide some sort of expiration, only a cache reset (e.g. server restart) will end up flushing the cache.
Unless you have infinite memory (and I'm pretty sure AWS doesn't provide that ;-) it is wise to add some expiration time to cached items.
Even though Memcached will expire items based on a least recently used mechanism (thanks @mikewied for pointing that out), the cache will still fill entirely before memcache begins evicting items based on LRU. Unfortunately, Memcache's LRU algorithm is per slab, not global. This means that LRU-based evictions can be less than optimal. See Memcached Memory Allocation and Optimization.
Upvotes: 3