简体   繁体   English

从Memcached哈希中删除特定键

[英]Deleting specific keys from memcached hash

I am trying to cache a table t_abc using memcached, for my rails application. 我正在尝试为我的Rails应用程序使用memcached缓存表t_abc。 The table has 50,000 entries. 该表有50,000个条目。 And I finally want have 20,000 keys(which will be of the form "abc_"+id). 最后,我希望有20,000个键(格式为“ abc _” + id)。 When the 20,001st entry is to be inserted in the cache, I want the least recently used key out of these 20,000(of the above form, and not some other keys in the memcached) to be deleted from the cache. 当要在高速缓存中插入第20001个条目时,我希望从高速缓存中删除这20,000个(上述形式的,而不是memcached中的其他一些密钥)中最近最少使用的密钥。 How do I achieve that? 我该如何实现?

NOTE: I am keeping an expiry = 0 for all the entries. 注意:我保持所有条目的到期时间= 0。

No, unfortunately you cannot efficiently do what you want to do with memcached. 不,不幸的是,您无法有效地使用memcached做您想做的事情。

It has a single LRU which works across all the data you are storing. 它只有一个LRU,可处理您存储的所有数据。 So if you are storing data from multiple tables then the fraction of the memcached entries taken up by each table depends on the relative patterns of access of the data from the different tables. 因此,如果您要存储多个表中的数据,则每个表所占用的内存缓存条目所占的比例取决于不同表中数据访问的相对模式。

So to control the amount of rows of the table are cached, really all you can do is adjust how big your memcached is and vary what other data gets stored. 因此,要控制缓存表的行数,实际上您所能做的就是调整内存缓存的大小并更改要存储的其他数据。

(Also, to evaluate the memcached configuration you might consider using a different metric, such as the hit rate or the median response time, rather than simply the number of rows cached.) (此外,要评估内存缓存的配置,您可以考虑使用其他指标,例如命中率或中位数响应时间,而不是简单地缓存的行数。)

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

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