简体   繁体   English

Memcached中的多个缓存

[英]Multiple caches in Memcached

I am migrating caches from EhCache to Memcached . 我正在将缓存从EhCache迁移到Memcached With only 1 Memcached instance, is there a way to have multiple caches (as in EhCache)? 只有一个Memcached实例,有没有办法拥有多个缓存(如在EhCache中)?

For example, I want to have a "Users" cache, a "Products" cache, etc... The main reason for that is to be able to monitor and configure each cache separately, and be able to clear them separately too. 例如,我想要一个“用户”缓存,一个“产品”缓存等......主要原因是能够分别监视和配置每个缓存,并且能够单独清除它们。

Typically, this sort of behavior is achieved in memcached via namespacing. 通常,这种行为是通过命名空间在memcached中实现的。 Within a single memcached instance, one maintains multiple namespaces, each of which represents a different cache. 在单个memcached实例中,一个维护多个名称空间,每个名称空间代表不同的缓存。 However, memcached doesn't natively support namespaces - instead, memcached namespaces are emulated by prefixing keys with a namespace identifier (eg, memcachedClient.get('products.top10') ). 但是,memcached本身不支持命名空间 - 相反,memcached命名空间通过为命名空间标识符添加前缀(例如, memcachedClient.get('products.top10') )来模拟。 Some memcached clients, like the Python GAE memcached client , abstract this behavior for you. 一些memcached客户端,如Python GAE memcached客户端 ,为您抽象出这种行为。 However, xmemcached does not, as far as I can tell. 但是,据我所知,xmemcached没有。

You are left with two options. 你有两种选择。

  • Manually prefix each key you work with. 手动为您使用的每个密钥添加前缀。
  • Write a thin wrapper around XMemcachedClient with two changes: it has a String namespace member that serves as the prefix value, and it overrides get0() to apply that prefix. 使用两个更改在XMemcachedClient周围写一个瘦包装器:它有一个String namespace成员作为前缀值,它覆盖get0()以应用该前缀。 This is a bit dangerous as it relies on the current XMemcached implementation. 这有点危险,因为它依赖于当前的XMemcached实现。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM