No description, website, or topics provided.
Ruby HTML CSS JavaScript
Switch branches/tags
Nothing to show
Clone or download

Build Status

Rails cache with locale

Automatically adding current application locale (I18n.locale) as a part of caching key in Rails views.

Problem & Solution

For example you have:

  • Rails app with different locales
  • you want to add fragment caching in views

When you have a different locales and you adding a caching you writing code like this

  = cache [@user, I18n.locale] do
    = render @user

As you see you need to add I18n.locale as a part of caching key. And you need to do it everywhere. What if you forget about it in some view?

This gem is a simple solution which allows you to DRY your code. So now you can write

  = cache @user do
    = render @user

And let gem handle all work. You don't need to specify locale as a cache sufix/prefix.


Just add this gem to your Gemfile.


Add this line to your application's Gemfile:

gem 'cache_with_locale'

And then execute:

$ bundle


Contribution directions go here.


The gem is available as open source under the terms of the MIT License.