Use RequestStore in CacheableAttributes.cached for greater performance
Signed-off-by: Rémy Coutable <remy@rymai.me>
This commit is contained in:
parent
a886532cc0
commit
4eda09e3fb
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue