Skip to content

Configure Monologue's cache

jipiboily edited this page Oct 10, 2012 · 6 revisions

Using page caching with Monologue

You've been able to turn on page caching with Monologue since the first release (0.1), but you now need a few more configurations to enable it starting with 0.2. Also, it now comes bundled with a smarter use of page caching, still not rocket science, but that could help for a lot of people.

To enable the use of page caching for Monologue, you must add this line in your config/initializers/monologue.rb file:

Monologue::PageCache.enabled = true

You also need to enable caching in your Rails project (in config/environments/production.rb):

   ActionController::Base.perform_caching = true

Automatic wipe, cache management (in admin) and rake task

There is now an optional auto-wipe after any save of published posts and also a cache management section in admin. You can completely wipe cache from that section if needed. Finally, there is a rake task to clear up the full cache. You could add a cron job to clear cache every, say, X minutes or hours.

To enable wipe

In config/initializers/monologue.rb, add:

Monologue::PageCache.wipe_enabled = true

Make sure that config.action_controller.page_cache_directory in config/environments/production.rb is set to a safe directory to completely wipe. It will wipe the whole directory. Let me say this again: it will wipe the whole directory. It will not work with the Rails public directory, it must be any other directory.

I suggest to have something like

config.action_controller.page_cache_directory = Rails.public_path + "/my-cache-dir"

Using the rake task to wipe cache

Simply call it like any other rake task:

bundle exec rake monologue:cache:wipe

I suggest the great whenever gem to set it as a cron job.

Clone this wiki locally