记忆快取到期时间 [英] memcached expiration time

查看:74
本文介绍了记忆快取到期时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Memcached提供了一个缓存过期时间选项,该选项指定对象在缓存中保留多长时间. 假设所有写入都通过缓存,我无法理解为什么有人要从缓存中删除一个对象.换句话说,如果所有写操作都在DB之前更新了缓存,那么该缓存永远不会包含过时的对象,那么为什么要删除它呢?

Memcached provides a cache expiration time option, which specifies how long objects are retained in the cache. Assuming all writes are through the cache I fail to understand why one would ever want to remove an object from the cache. In other words, if all write operations update the cache before the DB, then the cache can never contain a stale object, so why remove it?

一个可能的论点是,如果从不删除对象,则缓存将无限期增长,但是memcached允许您指定最大大小.一旦达到此大小,memcached将使用最近最少使用(LRU)算法来确定要删除的项目.总而言之,如果已经配置了合理的最大大小,并且所有写入都通过缓存,那么为什么要在一定时间后使对象过期?

One possible argument is that the cache will grow indefinitely if objects are never removed, but memcached allows you to specify a maximum size. Once this size is reached, memcached uses a least-recently-used (LRU) algorithm to determine which items to remove. To summarise, if a sensible maximum size has been configured, and all writes are through the cache, why would you want to expire objects after a certain length of time?

谢谢, 唐

推荐答案

当您不需要精确的信息,而只是希望它在一定时间内是精确的时,到期时间很有用.因此,您将数据缓存了(例如)五分钟.需要数据时,请检查缓存.如果在那里,请使用它.如果不是(因为它已过期),请重新计算该值.

Expiration times are useful when you don't need precise information, you just want it to be accurate to within a certain time. So you cache your data for (say) five minutes. When the data is needed, check the cache. If it's there, use it. If not (because it expired), then go and compute the value anew.

某些高速缓存的值基于大量数据,因此使高速缓存无效或向其写入新值是不切实际的.摘要数据或从大量原始数据中计算出的数据通常都是如此.

Some cached values are based on a large set of data, and invalidating the cache or writing new values to it is impractical. This is often true of summary data, or data computed from a large set of original data.

这篇关于记忆快取到期时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆