i18n
i18n copied to clipboard
Caching not working correctly Rails 5.0.6 ruby ruby 2.4.3p205
What I tried to do
I have tried adding i18n caching to my rails application using the steps outlined in cache.rb file. The keys are getting cached and retrieved, but a database call is being made anyway defeating the purpose of caching. I have put debug messages in the code and can tell that the base.rb translate and cache.rb translate are both being called. Below is some debug output from console
Here is the first translate that will write the key as you can see: `pry(main)> >> I18n.translate('items.index.slug_download_modal_title') [1] pry(main)> I18n.translate('items.index.slug_download_modal_title') here in base translate here in base translate (82.5ms) SELECT COUNT(*) FROM "translations" WHERE "translations"."locale" = $1 AND ("key" IN ('items.index.slug_download_modal_title') OR "key" LIKE 'items.index.slug_download_modal_title.%') [["locale", "en"]]
here in cache translate key:items.index.slug_download_modal_title fetching key:i18n//en/1505327406031908240/-4305939210704292139 No result from cache here in base translate writing key:i18n//en/1505327406031908240/-4305939210704292139 => "Batch Slug Report Download"`
Here is the second translate that has the key as you can see: `[2] pry(main)> >> I18n.translate('items.index.slug_download_modal_title') [2] pry(main)> I18n.translate('items.index.slug_download_modal_title')here in base translate *** this call should not be made*** here in base translate (379.7ms) SELECT COUNT(*) FROM "translations" WHERE "translations"."locale" = $1 AND ("key" IN ('items.index.slug_download_modal_title') OR "key" LIKE 'items.index.slug_download_modal_title.%') [["locale", "en"]]
here in cache translate key:items.index.slug_download_modal_title fetching key:i18n//en/1505327406031908240/-4305939210704292139 => "Batch Slug Report Download"`
What I expected to happen
I expect the db not to be queried and the value to be retrieved from the cache. I should not be seeing;
(379.7ms) SELECT COUNT(*) FROM "translations" WHERE "translations"."locale" = $1 AND ("key" IN ('items.index.slug_download_modal_title') OR "key" LIKE 'items.index.slug_download_modal_title.%') [["locale", "en"]]
If a key is found in the cache
What actually happened
Translate is being called and caching and lookup are being done..