質問

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).

  • User A and user B share a same resource.
  • User A login and read the shared resource cached in box1.
  • User B login and read the shared resource cached in box2.
  • User A updates the shared resource and expires the cache on box1
  • User B does not see the updated resource and still get the cached on in 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.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top