spree_cm_commissioner 2.5.3 → 2.5.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7e4c3bba39cc1a8f8a2cd7abdf91065bbd8caccfc1f574af9b5de4459822a5b3
4
- data.tar.gz: 0abd8b1b6e4c7c83260d6a958039ba59dc8f29284cf62e6ce5769ca8142aef16
3
+ metadata.gz: 7d93944d0194c1c575eca6f946b9b616ba4772fba61151fbc9b605464d87cb46
4
+ data.tar.gz: a0f1f687982be229cf5958a5f0ba0077eac693166dde8587c9a69df8bbf6caae
5
5
  SHA512:
6
- metadata.gz: ff309e440231910a83c35e4a70b0086eb21965e28a136952099893007b9ab09acd6a7a623129da5f15182a2edaac0b9a51692c0177036255838299d39600edea
7
- data.tar.gz: df15ec71ab9bfe6f9ad4f0bc20016085ffda814a3167758560e79f1f0e1397fa6fbd4202b37d1a8a46f1fd6b725d47440e85bf66fad283dbf80e46f8c4351236
6
+ metadata.gz: 978c11238f4ba63ff0e9e41444ca8d67046eab18d924996ad03dd4c64fe725285f225db7a9f8345220e60cb91b4147f915b8096eefc40c15453f2a090e115000
7
+ data.tar.gz: 9256c928528ebd0911aa5c4083ce477821d5117cfa379d205f8667fcbca17bd5e5f2052839d67079bf5627a4a56747f0e45d4ccb236c97831c6de6bdf45fec81
data/Gemfile.lock CHANGED
@@ -34,7 +34,7 @@ GIT
34
34
  PATH
35
35
  remote: .
36
36
  specs:
37
- spree_cm_commissioner (2.5.3)
37
+ spree_cm_commissioner (2.5.4)
38
38
  activerecord-multi-tenant
39
39
  activerecord_json_validator (~> 2.1, >= 2.1.3)
40
40
  aws-sdk-cloudfront
@@ -1,3 +1,5 @@
1
+ # Check following file for spec:
2
+ # spec/controllers/application_controller_spec.rb
1
3
  module SpreeCmCommissioner
2
4
  module ContentCachable
3
5
  extend ActiveSupport::Concern
@@ -6,9 +8,64 @@ module SpreeCmCommissioner
6
8
  after_action :set_cache_control_for_cdn
7
9
  end
8
10
 
11
+ # Cache duration priorities by content type
12
+ # Priority 1: Static/Rarely Changed (1 day)
13
+ STATIC_CONTENT_CONTROLLERS = %w[
14
+ CountriesController
15
+ ProvincesController
16
+ GuestCardClassesController
17
+ SeatLayoutController
18
+ CmsPagesController
19
+ ].freeze
20
+
21
+ # Priority 2: Semi-Static (1 hour)
22
+ SEMI_STATIC_CONTROLLERS = %w[
23
+ MenusController
24
+ HomepageBackgroundController
25
+ HomepageDataController
26
+ PopularRoutesController
27
+ RoutePlacesController
28
+ ].freeze
29
+
30
+ # Priority 3: Moderate Freshness (30 minutes)
31
+ MODERATE_FRESHNESS_CONTROLLERS = %w[
32
+ HomepageSectionsController
33
+ TaxonsController
34
+ ProductsController
35
+ EventsController
36
+ EventMatchesController
37
+ AccommodationsController
38
+ VendorsController
39
+ VendorPhotosController
40
+ DynamicFieldsController
41
+ ].freeze
42
+
43
+ # Priority 4: High Freshness (5 minutes)
44
+ HIGH_FRESHNESS_CONTROLLERS = %w[
45
+ TripsController
46
+ TripSearchController
47
+ ].freeze
48
+
49
+ def shared_max_age
50
+ ENV.fetch('CACHE_CDN_MAX_AGE', 1.day.to_i).to_i
51
+ end
52
+
9
53
  # Override This Method based on your UseCase
10
- def max_age
11
- ENV.fetch('CONTENT_CACHE_MAX_AGE', 1.day.to_i).to_i
54
+ # Or let it auto-detect based on controller name
55
+ def client_max_age
56
+ controller_name = self.class.name.demodulize
57
+
58
+ if STATIC_CONTENT_CONTROLLERS.include?(controller_name)
59
+ ENV.fetch('CACHE_STATIC_MAX_AGE', 1.day.to_i).to_i
60
+ elsif SEMI_STATIC_CONTROLLERS.include?(controller_name)
61
+ ENV.fetch('CACHE_SEMI_STATIC_MAX_AGE', 1.hour.to_i).to_i
62
+ elsif MODERATE_FRESHNESS_CONTROLLERS.include?(controller_name)
63
+ ENV.fetch('CACHE_MODERATE_MAX_AGE', 30.minutes.to_i).to_i
64
+ elsif HIGH_FRESHNESS_CONTROLLERS.include?(controller_name)
65
+ ENV.fetch('CACHE_REALTIME_MAX_AGE', 5.minutes.to_i).to_i
66
+ else
67
+ ENV.fetch('CACHE_DEFAULT_MAX_AGE', 5.minutes.to_i).to_i
68
+ end
12
69
  end
13
70
 
14
71
  def set_cache_control_for_cdn
@@ -17,12 +74,7 @@ module SpreeCmCommissioner
17
74
 
18
75
  # max-age: browser/client cache, s-maxage: CDN/server cache
19
76
  # Allow client caching for mobile apps while keeping CDN cache longer
20
- client_max_age = [max_age / 2, 300].max # At least 5 minutes, or half of CDN cache
21
- response.headers['Cache-Control'] = "public, max-age=#{client_max_age}, s-maxage=#{max_age}"
22
-
23
- # Pragma: HTTP/1.0 cache directive (predates Cache-Control).
24
- # 'cache' allows caching.
25
- response.headers['Pragma'] = 'cache'
77
+ response.headers['Cache-Control'] = "public, max-age=#{client_max_age}, s-maxage=#{shared_max_age}"
26
78
 
27
79
  # Expires: Absolute timestamp when cache becomes stale (HTTP/1.0 fallback)
28
80
  response.headers['Expires'] = (Time.zone.now + client_max_age).httpdate
@@ -1,5 +1,5 @@
1
1
  module SpreeCmCommissioner
2
- VERSION = '2.5.3'.freeze
2
+ VERSION = '2.5.4'.freeze
3
3
 
4
4
  module_function
5
5
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spree_cm_commissioner
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.5.3
4
+ version: 2.5.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - You