According to https://github.com/mperham/dalli, we can configure multiple Memcache servers. But I'm not sure how it works.
Assume that we're using a memcache cluster with two servers: memcache1(box1) and memcache2 (box2).
It's my understanding so far, I'm not sure how the cache expiration works in cluster environment. Especially, when we want to eagerly expire the cache, will it expire on all boxes?
Given we have a same configuration like this in TWO rails servers:
config.cache_store = :dalli_store, 'memcache1', 'memcache2'
How do you think about this use case?
Thanks for your all interest.
Memcached sharding is sharding, not replication. That is, there isn't a copy of the data on each server; the data is split up between servers.
Keys will only ever exist on one server. Dalli passes keys through a distribution algorithm to determine which server will own a given key, then passes messages to that server. The same keys will not exist on multiple servers, so you don't have to worry about expiring the keys on both of them at once. If you expire the key, it will be expired on the single box that it lives on.
If both users are requesting data via the same cache key, then expiring that cache key will invalidate it for both of them; you don't have to worry about User 1 getting routed to Box 1, and User 2 getting routed to Box 2, because a given key will always map to a given server.