1

I set 10000 keys in memcache

for i in 1..10000
  Rails.cache.write("short_key#{i}", i)
end

After ~500s (not benchmarked but happens around 10m), when I do

_random = rand(10000) 
Rails.cache.read("short_key#{_random}")

returns nil. This is fine. Memcached LRU policy might have destroyed those keys.

But, issue is I see a lot of free memory on server.

Also, when I run following command in telnet session,

stats cachedump 1 10

I get some random keys which I set earlier in loop and even when I try to fetch them via rails or telnet/get, memcached is not able to read that value.

Those key/values are eating up memory but somehow getting destroyed.

I use dalli to connect with memcached.

How can I correct this?

Anshul Goyal
  • 73,278
  • 37
  • 149
  • 186
geek_guy
  • 607
  • 1
  • 5
  • 17

1 Answers1

0

At first glance, this seems possible if the default keep alive time value is low (10 minutes or 500 seconds are both possible default values).

Since you are not setting up the expires_in (or equivalent time_to_live field), the key will be setup for default time, after which the value will expire.

Referring here:

Setting :expires_in will set an expiration time on the cache. All caches support auto-expiring content after a specified number of seconds. This value can be specified as an option to the constructor (in which case all entries will be affected), or it can be supplied to the fetch or write method to effect just one entry.

Anshul Goyal
  • 73,278
  • 37
  • 149
  • 186
  • I don't think `:expires_in ` is the issue. Because it defaults for dalli default ttl is 0, which means no expiry. Also, When we use some keys frequently, they don't go away. – geek_guy Aug 18 '15 at 10:27
  • @geek_guy how much memory does your memcached have? – Anshul Goyal Aug 18 '15 at 10:47
  • 1
    16 GB. It has 7.5 GB free memory right now. So I don't think its LRU causing the key evictions. – geek_guy Aug 18 '15 at 12:31