を使用してキャッシュするオブジェクトを作成しています
class Foo
attr_accessor :bar
end
foo = Foo.new
foo.bar = "123"
Rails.write "key", foo
電話すると
Rails.read "key"
同じリクエストで - オブジェクトが取得されます。ただし、他のリクエスト/他のRailsプロセスで呼び出すと、nilになります。
単純なオブジェクトの保存 (数値、文字列、数値の配列など)
Rails.cache データ:
pry(main)> Rails.cache
=> #<ActiveSupport::Cache::DalliStore:0x007fa42906d5b8
@data=
#<Dalli::Client:0x007fa42906d478
@options={:expires_in=>0},
@ring=
#<Dalli::Ring:0x007fa423bc0ad8
@continuum=nil,
@failover=true,
@servers=
[#<Dalli::Server:0x007fa423bc0c90
@down_at=nil,
@error=nil,
@fail_count=0,
@hostname="localhost",
@last_down_at=nil,
@lock=
#<Monitor:0x007fa423bc0970
@mon_count=0,
@mon_mutex=#<Mutex:0x007fa423bc0858>,
@mon_owner=nil>,
@msg=nil,
@options=
{:down_retry_delay=>1,
:socket_timeout=>0.5,
:socket_max_failures=>2,
:socket_failure_delay=>0.01,
:value_max_bytes=>1048576,
:username=>nil,
:password=>nil,
:async=>false,
:expires_in=>0},
@port=11211,
@sock=#<Dalli::Server::KSocket:fd 11>,
@version="1.4.13",
@weight=1>]>,
@servers=["localhost:11211"]>,