Configure Monologue's cache

Jean-Philippe Boily edited this page Feb 12, 2014 · 6 revisions

IMPORTANT: This is for Monologue BEFORE 0.4. Do not use this with 0.4 & up

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 # this alone will enable cache management's UI and rake task, but not automatic wipe after save.
Monologue::PageCache.wipe_after_save = true # **needed** for automatic wipe after saving a published post.

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.

IMPORTANT for root mounted Monologue instances

IMPORTANT: if monologue is mounted at root ("/"), you must also add that in your routes.rb file, before the monologue mount:

root to: 'monologue/posts#index'
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.