Skip to content

igorkasyanchuk/cache_with_locale

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
bin
 
 
lib
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

RailsJazz https://www.patreon.com/igorkasyanchuk Listed on OpenSource-Heroes.com

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.

This gem also works for collection caching like this:

  = render partial: :post, collection: @posts, cached: true

Usage

Just add this gem to your Gemfile.

Installation

Add this line to your application's Gemfile:

gem 'cache_with_locale'

And then execute:

$ bundle

Contributing

Contributors:

Change Log

0.0.3

0.0.2

0.0.1

  • initial version, ready for production

License

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

About

Easy wait to do view caching with automatically added "locale" value to the cached key.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

Packages

No packages published