Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where to configure Rails 3 cache_store?

I'm trying to configure Rails 3 cache_store with something like this in environments/development.rb:

config.cache_store = :memory_store, {:size => 64.megabytes, :expires_in => 5.minutes}

But when i start server i get:

undefined method `megabytes' for 64:Fixnum (NoMethodError)

Probably something is not loaded yet.

My question is: where is the right place to configure it them? Where should i place this code?

like image 738
Fernando Avatar asked Apr 17 '12 22:04

Fernando


People also ask

Where is Rails cache stored?

Page caches are always stored on disk. Rails 2.1 and above provide ActiveSupport::Cache::Store which can be used to cache strings. Some cache store implementations, like MemoryStore, are able to cache arbitrary Ruby objects, but don't count on every cache store to be able to do that.

How do I access Rails cache?

Alternatively, you can set ActionController::Base. cache_store outside of a configuration block. You can access the cache by calling Rails. cache .

What is caching and how it works?

In computing, a cache is a high-speed data storage layer which stores a subset of data, typically transient in nature, so that future requests for that data are served up faster than is possible by accessing the data's primary storage location.


2 Answers

Or else add this line

require 'active_support/core_ext/numeric/bytes'

before

config.cache_store = :memory_store, {:size => 64.megabytes, :expires_in => 5.minutes}
like image 166
jang00 Avatar answered Oct 17 '22 02:10

jang00


Use ActionController::Base.cache_store = and place in an initializer file (create an rb file in config/initializers)

like image 41
Nick Colgan Avatar answered Oct 17 '22 00:10

Nick Colgan