Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails: control file store cache size

The documentation for the file-based cache in rails says:

Note that the cache will grow until the disk is full unless you periodically clear out old entries.

Unfortunately it doesnt give any information about how to clear old entries periodically. Does setting an appropriate value for :expires_in do the job or is there some other sort of black magic behind clearing the cache?

Also, the documenation gives an option to limit the memory-based cache in size:

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

Does this also work for the file based cache? And even more importantly, what happens when the cache growths below that size limit? Does it remove old cached values or will it throw some kind of exception?

thanks in advance, danijoo

like image 600
danijoo Avatar asked Mar 11 '14 18:03

danijoo


2 Answers

Experimenting with FileStore cache I found that :expires_in options works, but :size one doesn't.

If you want to specify options then you need to also specify the path, try with the following example:

config.cache_store = :file_store, Rails.root.join('tmp', 'cache'), { expires_in: 1.minute }

Put the code in config/application.rb and remember to activate the cache in config/environments/development.rb and restart the app.

P.S. I use 1 minute to easily do a quick test.

like image 165
Mauro Nidola Avatar answered Oct 14 '22 00:10

Mauro Nidola


Yes the limit applies in case of file-based cache too. And yes a value for :expires_in will do the job.

When this limit is reached, no further stuff will be cached. No exception is thrown.

like image 33
Agis Avatar answered Oct 14 '22 00:10

Agis