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
...@@ -25,7 +25,11 @@ module CacheableAttributes ...@@ -25,7 +25,11 @@ module CacheableAttributes
end end
def cached def cached
retrieve_from_cache if RequestStore.active?
RequestStore[:"#{name}_cached_attributes"] ||= retrieve_from_cache
else
retrieve_from_cache
end
end end
def retrieve_from_cache def retrieve_from_cache
......
...@@ -177,6 +177,15 @@ describe CacheableAttributes do ...@@ -177,6 +177,15 @@ describe CacheableAttributes do
end end
end 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 end
describe '.cached', :use_clean_rails_memory_store_caching do 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