Commit 4eda09e3 authored by Rémy Coutable's avatar Rémy Coutable

Use RequestStore in CacheableAttributes.cached for greater performance

Signed-off-by: default avatarRémy Coutable <remy@rymai.me>
parent a886532c
No related merge requests found
......@@ -25,7 +25,11 @@ module CacheableAttributes
end
def cached
retrieve_from_cache
if RequestStore.active?
RequestStore[:"#{name}_cached_attributes"] ||= retrieve_from_cache
else
retrieve_from_cache
end
end
def retrieve_from_cache
......
......@@ -177,6 +177,15 @@ describe CacheableAttributes do
end
end
end
it 'uses RequestStore in addition to Rails.cache', :request_store do
# Warm up the cache
create(:application_setting).cache!
expect(Rails.cache).to receive(:read).with(ApplicationSetting.cache_key).once.and_call_original
2.times { ApplicationSetting.current }
end
end
describe '.cached', :use_clean_rails_memory_store_caching do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment