如何使用 dalli 和 Rails 将内存缓存块大小增加到 1MB 以上?

Zac*_* Xu 3 memcached ruby-on-rails dalli

我正在使用 Ruby on Rails 和 dalli gem 来使用 memcache 进行缓存。

默认值(键值存储中的值,又名slab)最大大小为1MB。

我想将其增加到 2MB。

dalli 的文档说:

value_max_bytes: The maximum size of a value in memcached. Defaults to 1MB, this can be increased with memcached's -I parameter. You must also configure Dalli to allow the larger size here.

使用-I选项时memcached,如何指定 2MB?是 -I2 还是 -I2000?(文档对此不清楚)

对于达利宝石,我有,在 environments/development.rb

config.cache_store = :dalli_store
Run Code Online (Sandbox Code Playgroud)

我没有明确提到 Dalli::Client.new 那么我该如何设置value_max_bytes

我查看了有关 stackoverflow 的相关问题,看来我需要安装 rack-cache gem。这是必要的吗?

谢谢你。

Zac*_* Xu 5

memcached使用以下命令启动:

memcached -p 11211 -I2m
Run Code Online (Sandbox Code Playgroud)

在 Rails 环境文件中,例如 config/environments/production.rb,使用以下语法:

config.cache_store = :dalli_store, { value_max_bytes: 2000000 }
Run Code Online (Sandbox Code Playgroud)