locomotivecms/liquid_extensions — pull request #10 by conroywhitney (2014-12-17 00:44:32+00:00)
Title: Cache Liquid block wrapping Rails.cache.fetch

Thank you for all of your work on LocomotiveCMS!

This pull request is for a `{% cache %}` liquid block which functions like [Rails fragment caching](http://guides.rubyonrails.org/caching_with_rails.html#fragment-caching). Behind the scenes, it calls `Rails.cache.fetch` which, if `dalli` is configured correctly on the LocomotiveCMS Engine, will make a call to a memcache-like datastore. If it is not configured, it will simply evaluate the block.

I created this to speed up a ["View All" SEO pagination page](http://moz.com/ugc/seo-guide-to-google-webmaster-recommendations-for-pagination) which was looping through many content entries and rendering snippets which resulted in many sequential MongoDB calls. The trade-off to having a single call to render this whole block is needing to manually call `Rails.cache.clear` after a content change. I am sure there is a better way around this!

I have a corresponding `cache-hosting` branch that I will submit a pull request into the `hosting` branch.