我们有:
Rails.cache.fetch("google.com/videos", expires_in: 12.hours) { # some request }
Rails.cache.fetch("google.com/images", expires_in: 12.hours) { # some request }
Rails.cache.fetch("stackoverflow.com/questions", expires_in: 12.hours) { # some request }
如何通过 "google.com"
键或 "stackoverflow.com"
使 Rails 缓存过期?
最佳答案
如果您使用默认缓存存储,即 FileStore或MemoryStore ,使用 delete_matched
method 应该可以仅删除键的子集。 ,例如:
Rails.cache.delete_matched(/^google\.com/)
如果您使用 memcached,这是不可能的,您必须手动删除 fetch
调用中使用的所有键。或者,根本不用担心过期,而是使用在每次相关更改及其包含的数据时更改的 key ,请参见例如this blog post .
关于ruby-on-rails - 如何按命名空间手动使 Rails 低缓存过期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36152755/