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
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With