mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Move cache keys used in views into the cache service
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user