ActiveSupport::Cache::Strategy::LocalCache 有什么用? [英] What is ActiveSupport::Cache::Strategy::LocalCache used for?

查看:48
本文介绍了ActiveSupport::Cache::Strategy::LocalCache 有什么用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我所有环境的生产中间件堆栈中,我看到了这个一次性实例:

In my production middleware stack in all environments I see this one-off instance:

use #<ActiveSupport::Cache::Strategy::LocalCache::Middleware:0x7f38095d>

我已经尝试删除我能想到的与缓存相关的所有内容,但我无法弄清楚它的来源.

I've experimented by removing everything I can think of related to caching, but I'm unable to figure out where it comes from.

这是什么?

推荐答案

抽象地说,它在一个块的持续时间内用内存中的缓存包装另一个缓存,然后在块之后清除.

In the abstract, it wraps another cache with an in-memory cache for the duration of a block, and then is cleared after the block.

在实践中,我相信它在 Rails/Rack 中用于将您配置的任何缓存(memcached、磁盘)包装在内存缓存中,该缓存在请求结束时被清除.这个想法是,如果您在一个请求中两次获取相同的缓存键,它将在第一个请求时缓存在包装的 LocalCache 中,并在第二个请求时从内存加载(而不是再次访问 memcached 服务器/磁盘).

In practice I believe it is used in Rails/Rack to wrap whatever cache you have configured (memcached, disk) with an in-memory cache which is cleared at the end of the request. The idea is that if you fetch the same cache key twice in one request, it will be cached in the wrapping LocalCache on the first request and will loaded from memory on the second request (instead of reaching out to the memcached server/disk again).

来自文档:

实现 LocalCache 的缓存将在一个块的持续时间内由内存缓存支持.为同一个键重复调用缓存将命中内存缓存以加快访问速度.

Caches that implement LocalCache will be backed by an in-memory cache for the duration of a block. Repeated calls to the cache for the same key will hit the in-memory cache for faster access.

Git 历史:https://github.com/rails/rails/commits/master/activesupport/lib/active_support/cache/strategy/local_cache.rb

RDoc:http://api.rubyonrails.org/classes/ActiveSupport/Cache/Strategy/LocalCache.html

这篇关于ActiveSupport::Cache::Strategy::LocalCache 有什么用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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