Update Fragment Caching for Rails 4

Rails 4 introduced "automagically" modified cache keys, that included a digest in the key on any cache entry related to views. This is not what we want at all, fixed here with the `skip_digest: true` option.
This commit is contained in:
Matt-Yorkley
2020-05-22 13:44:27 +02:00
parent a9abe48ede
commit b00fbd69ae
3 changed files with 18 additions and 12 deletions

View File

@@ -37,25 +37,31 @@ class CacheService
# Rails' caching in views is called "Fragment Caching" and uses some slightly different logic.
# Note: keys supplied here are actually prepended with "views/" under the hood.
def self.ams_all_taxons_key
"inject-all-taxons-#{CacheService.latest_timestamp_by_class(Spree::Taxon)}"
def self.ams_all_taxons
[
"inject-all-taxons-#{CacheService.latest_timestamp_by_class(Spree::Taxon)}",
{ skip_digest: true }
]
end
def self.ams_all_properties_key
"inject-all-properties-#{CacheService.latest_timestamp_by_class(Spree::Property)}"
def self.ams_all_properties
[
"inject-all-properties-#{CacheService.latest_timestamp_by_class(Spree::Property)}",
{ skip_digest: true }
]
end
def self.ams_shops
[
"shops/index/inject_enterprises",
{ expires_in: SHOPS_EXPIRY }
{ expires_in: SHOPS_EXPIRY, skip_digest: true }
]
end
def self.ams_shop(enterprise)
[
"enterprises/shop/inject_enterprise_shopfront-#{enterprise.id}",
{ expires_in: SHOPS_EXPIRY }
{ expires_in: SHOPS_EXPIRY, skip_digest: true }
]
end
end

View File

@@ -48,9 +48,9 @@
= inject_current_hub
= inject_current_user
= inject_rails_flash
- cache CacheService::FragmentCaching.ams_all_taxons_key do
- cache(*CacheService::FragmentCaching.ams_all_taxons) do
= inject_taxons
- cache CacheService::FragmentCaching.ams_all_properties_key do
- cache(*CacheService::FragmentCaching.ams_all_properties) do
= inject_properties
= inject_current_order
= inject_currency_config

View File

@@ -33,10 +33,10 @@ feature "Darkswarm data caching", js: true, caching: true do
visit shops_path
taxon_timestamp1 = CacheService.latest_timestamp_by_class(Spree::Taxon)
expect_cached "views/#{CacheService::FragmentCaching.ams_all_taxons_key}"
expect_cached "views/#{CacheService::FragmentCaching.ams_all_taxons[0]}"
property_timestamp1 = CacheService.latest_timestamp_by_class(Spree::Property)
expect_cached "views/#{CacheService::FragmentCaching.ams_all_properties_key}"
expect_cached "views/#{CacheService::FragmentCaching.ams_all_properties[0]}"
toggle_filters
@@ -54,10 +54,10 @@ feature "Darkswarm data caching", js: true, caching: true do
visit shops_path
taxon_timestamp2 = CacheService.latest_timestamp_by_class(Spree::Taxon)
expect_cached "views/#{CacheService::FragmentCaching.ams_all_taxons_key}"
expect_cached "views/#{CacheService::FragmentCaching.ams_all_taxons[0]}"
property_timestamp2 = CacheService.latest_timestamp_by_class(Spree::Property)
expect_cached "views/#{CacheService::FragmentCaching.ams_all_properties_key}"
expect_cached "views/#{CacheService::FragmentCaching.ams_all_properties[0]}"
expect(taxon_timestamp1).to_not eq taxon_timestamp2
expect(property_timestamp1).to_not eq property_timestamp2