I am using redis-rails. For cache key I am using an array:
Rails.cache.fetch([self.class.name, :translated_attribute, id, field, I18n.locale]) do
self.read_at
The default rails cache key format is: [class]/[id]-[timestamp]
i usually dont use rails default cache key format, instead i create my own keys so it would be easier to manipulate in redis.
cache_key = "#{self.class.name}/#{translated_attribute}/#{id}/#{field}/#{I18n.locale}"
Rails.cache.fetch(cache_key) do
self.read_attribute field, locale: I18n.locale
end
Rails.cache.delete(cache_key)
Rails.cache.delete_matched("#{self.class.name}*#{id}*")