gpt4 book ai didi

ruby-on-rails - 从内存存储更改为 memcached 存储时,Rails.cache 抛出 "marshal dump"错误

转载 作者:行者123 更新时间:2023-12-04 23:57:06 25 4
gpt4 key购买 nike

如果我在我的环境中设置它

config.action_controller.cache_store = :mem_cache_store
ActionController::Base.cache_store将使用 memcached 存储,但 Rails.cache 将使用内存存储:
$ ./script/console
>> ActionController::Base.cache_store
=> #<ActiveSupport::Cache::MemCacheStore:0xb6eb4bbc @data=<MemCache: 1 servers, ns: nil, ro: false>>
>> Rails.cache
=> #<ActiveSupport::Cache::MemoryStore:0xb78b5e54 @data={}>

在我的应用程序中,我使用 Rails.cache.fetch(key){ object }在我的助手中缓存对象。一直以来,我都假设 Rails.cache使用 memcached 存储,所以我很惊讶它使用内存存储。

如果我更改 cache_store在我的环境中设置为
config.cache_store = :mem_cache_store

ActionController::Base.cache_store 和 Rails.cache 现在将使用相同的内存存储,这正是我所期望的:
$ ./script/console
>> ActionController::Base.cache_store
=> #<ActiveSupport::Cache::MemCacheStore:0xb7b8e928 @data=<MemCache: 1 servers, ns: nil, ro: false>, @middleware=#<Class:0xb7b73d44>, @thread_local_key=:active_support_cache_mem_cache_store_local_cache>
>> Rails.cache
=> #<ActiveSupport::Cache::MemCacheStore:0xb7b8e928 @data=<MemCache: 1 servers, ns: nil, ro: false>, @middleware=#<Class:0xb7b73d44>, @thread_local_key=:active_support_cache_mem_cache_store_local_cache>

但是,当我运行该应用程序时,在我调用 Rails.cache.fetch(key){ object } 的行中出现“marshal dump”错误。
no marshal_dump is defined for class Proc

Extracted source (around line #1):
1: Rails.cache.fetch(fragment_cache_key(...), :expires_in => 15.minutes) { ... }

vendor/gems/memcache-client-1.8.1/lib/memcache.rb:359:in 'dump'
vendor/gems/memcache-client-1.8.1/lib/memcache.rb:359:in 'set_without_newrelic_trace'

是什么赋予了?是 Rails.cache意味着是一个内存存储?我应该打电话 controller.cache_store.fetch在我打电话的地方 Rails.cache.fetch ?

最佳答案

您不能编码(marshal)包含 procs 或 lambdas 的对象。这是 Ruby 解释器的当前限制。你究竟在缓存中存储了什么?整个对象?还是只有身份证?告诉我你在缓存中存储了什么,有人可以帮助你弄清楚。

关于ruby-on-rails - 从内存存储更改为 memcached 存储时,Rails.cache 抛出 "marshal dump"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2591332/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com