Class: Ci::RetentionPolicies::PipelineDeletionCutoffCache
- Inherits:
-
Object
- Object
- Ci::RetentionPolicies::PipelineDeletionCutoffCache
- Defined in:
- lib/ci/retention_policies/pipeline_deletion_cutoff_cache.rb
Overview
Cache the last deletion timestamp for pipeline cleanup operations per project and status.
This class provides Redis-based storage for caching the last processed pipeline’s created_at timestamp for a given project grouped by status to avoid querying of old data, thereby improving performance.
The Redis key includes both project ID and the project’s pipeline retention setting to ensure cache invalidation when retention policies change.
Constant Summary collapse
- REDIS_KEY_FMT =
'ci_old_pipelines_removal_cache_%{config}:{%{project_id}}'- REDIS_KEY_TTL =
to prevent stale data
1.week.to_i
Instance Method Summary collapse
- #clear ⇒ Object
-
#initialize(project:) ⇒ PipelineDeletionCutoffCache
constructor
A new instance of PipelineDeletionCutoffCache.
-
#read ⇒ Hash<String, Time>
Hash of status => timestamp pairs, empty hash if no data.
-
#write(values) ⇒ String?
‘OK’ if successful, nil otherwise.
Constructor Details
#initialize(project:) ⇒ PipelineDeletionCutoffCache
Returns a new instance of PipelineDeletionCutoffCache.
33 34 35 |
# File 'lib/ci/retention_policies/pipeline_deletion_cutoff_cache.rb', line 33 def initialize(project:) @project = project end |
Instance Method Details
#clear ⇒ Object
58 59 60 61 62 |
# File 'lib/ci/retention_policies/pipeline_deletion_cutoff_cache.rb', line 58 def clear with_redis do |redis| redis.del(key) end end |
#read ⇒ Hash<String, Time>
Returns Hash of status => timestamp pairs, empty hash if no data.
48 49 50 51 52 53 54 55 56 |
# File 'lib/ci/retention_policies/pipeline_deletion_cutoff_cache.rb', line 48 def read with_redis do |redis| Gitlab::Json.parse(redis.get(key)) .to_h .transform_values { || Time.iso8601() } end rescue JSON::ParserError {} end |
#write(values) ⇒ String?
Returns ‘OK’ if successful, nil otherwise.
39 40 41 42 43 44 45 |
# File 'lib/ci/retention_policies/pipeline_deletion_cutoff_cache.rb', line 39 def write(values) return if values.empty? with_redis do |redis| redis.set(key, values.compact.to_json, ex: REDIS_KEY_TTL) end end |