Working with rails caching

Rails.cache.write(‘name’,‘Hello this is string’ , :expires_in => 1.week)
Rails.cache.read(‘name’)

i use these syntax but always it’s nil
=> nil

1 Like

What do you get if you just as for the cache store in a console?

Rails.cache # e.g. => #<ActiveSupport::Cache::ResilientRedisStore...>

You might not have set you

config.cache_store

to anything in your config/application.rb. Try setting it to :memory_store.

1 Like

As @madsohm suggested,

In your: config/environments/development.rb (it can also be production.rb or others):

config.cache_store = :memory_store, { size: 64.megabytes } 

You can also do a quick read here. :wink: