簡體   English   中英

從內存存儲更改為Memcached存儲時,Rails.cache會引發“封送轉儲”錯誤

[英]Rails.cache throws “marshal dump” error when changed from memory store to memcached store

如果我在環境中設置

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是否打算成為內存存儲? 我應該在我稱為Rails.cache.fetch的地方調用controller.cache_store.fetch嗎?

您無法封送其中包含proc或lambda的對象。 這是Ruby解釋器的當前限制。 您究竟將什么存儲在緩存中? 整個對象? 還是只是ID? 請告訴我您存儲在緩存中的內容,然后有人可以幫助您解決該問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM