Move cache keys used in views into the cache service

This commit is contained in:
Matt-Yorkley
2020-04-30 09:45:02 +02:00
parent 210029aaff
commit a35f8cdb02
2 changed files with 15 additions and 2 deletions

View File

@@ -20,4 +20,17 @@ class CacheService
def self.latest_timestamp_by_class(cached_class)
cached_class.maximum(:updated_at).to_i
end
module FragmentCaching
# Rails' caching in views is called "Fragment Caching" and uses some slightly different logic.
# Note: supplied keys are actually prepended with "view/" under the hood.
def self.ams_all_taxons_key
"inject-all-taxons-#{CacheService.latest_timestamp_by_class(Spree::Taxon)}"
end
def self.ams_all_properties_key
"inject-all-properties-#{CacheService.latest_timestamp_by_class(Spree::Property)}"
end
end
end

View File

@@ -48,9 +48,9 @@
= inject_current_hub
= inject_current_user
= inject_rails_flash
- cache "inject-all-taxons-#{CacheService.latest_timestamp_by_class(Spree::Taxon)}" do
- cache CacheService::FragmentCaching.ams_all_taxons_key do
= inject_taxons
- cache "inject-all-properties-#{CacheService.latest_timestamp_by_class(Spree::Property)}" do
- cache CacheService::FragmentCaching.ams_all_properties_key do
= inject_properties
= inject_current_order
= inject_currency_config