Class: Gitlab::Pages::CacheControl
- Inherits:
-
Object
- Object
- Gitlab::Pages::CacheControl
- Includes:
- Utils::StrongMemoize
- Defined in:
- lib/gitlab/pages/cache_control.rb
Constant Summary collapse
- EXPIRE =
12.hours
- DEPLOYMENT_EXPIRATION =
To avoid delivering expired deployment URL in the cached payload, use a longer expiration time in the deployment URL
(EXPIRE + 12.hours)
- SETTINGS_CACHE_KEY =
'pages_domain_for_%{type}_%{id}'
- PAYLOAD_CACHE_KEY =
'%{settings_cache_key}_%{settings_hash}'
Class Method Summary collapse
Instance Method Summary collapse
- #cache_key ⇒ Object
-
#clear_cache ⇒ Object
Invalidates the cache.
-
#initialize(type:, id:) ⇒ CacheControl
constructor
A new instance of CacheControl.
Constructor Details
#initialize(type:, id:) ⇒ CacheControl
Returns a new instance of CacheControl.
28 29 30 31 32 33 |
# File 'lib/gitlab/pages/cache_control.rb', line 28 def initialize(type:, id:) raise(ArgumentError, "type must be :namespace or :domain") unless %i[namespace domain].include?(type) @type = type @id = id end |
Class Method Details
.for_domain(domain_id) ⇒ Object
19 20 21 |
# File 'lib/gitlab/pages/cache_control.rb', line 19 def for_domain(domain_id) new(type: :domain, id: domain_id) end |
.for_namespace(namespace_id) ⇒ Object
23 24 25 |
# File 'lib/gitlab/pages/cache_control.rb', line 23 def for_namespace(namespace_id) new(type: :namespace, id: namespace_id) end |
Instance Method Details
#cache_key ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/gitlab/pages/cache_control.rb', line 35 def cache_key strong_memoize(:payload_cache_key) do cache_settings_hash! payload_cache_key_for(settings_hash) end end |
#clear_cache ⇒ Object
Invalidates the cache.
Since rails nodes and sidekiq nodes have different application settings, and the invalidation happens in a sidekiq node, we have to use the cached settings hash to build the payload cache key to be invalidated.
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/gitlab/pages/cache_control.rb', line 48 def clear_cache keys = cached_settings_hashes .map { |hash| payload_cache_key_for(hash) } .push(settings_cache_key) ::Gitlab::AppLogger.info( message: 'clear pages cache', pages_keys: keys, pages_type: @type, pages_id: @id ) Gitlab::Instrumentation::RedisClusterValidator.allow_cross_slot_commands do Rails.cache.delete_multi(keys) end end |