Go back to the blog

AMA: How to design keys for the partial caching?

As a self-made convention we recommend a following signature of the cache (key):

‘’’[ I18n.locale, @user_account, @cached_object, other_dynamic_data… ]’’’

Sometimes I also prefix the locale part with the context of the partial, e.g. 'homepage' or 'notification_feed'

This way each locale and user have their own cached view — one can also use a dynamic solution like loading dynamic data using JavaScript, although it's easier to just invalidate the cache and call it a day for simplicity.

This works great until one needs real-time updates, then using dynamic JavaScript loading or ActionCable events would be a good way to go!

This is a question asked during an AMA (Ask Me Anything) session — follow the blog to keep up with the common engineering questions and answers, or join our free mentoring platform!

Read more articles like this one:

Code Architecture 5 Ruby on Rails 8