Skip to content

Import::Caching sets TTL greater than existing

What does this MR do and why?

This MR changes the Gitlab::Cache::Import::Caching.read, .increment, and .increment_by methods to now only set an expiry time for a key if it is greater than the existing TTL.

This fixes a bug where .read would set the TTL to a much lower value in some situations #427097 (comment 1615773392)

How to set up and validate locally

Gitlab::Cache::Import::Caching.write('134940:write', 'bar')
Gitlab::Cache::Import::Caching.read('134940:write', timeout: 1)
# Wait 2 seconds...
Gitlab::Cache::Import::Caching.read('134940:write', timeout: 1) # => Will return `"bar"` on this branch, but `nil` on master

Gitlab::Cache::Import::Caching.increment_by('134940:increment_by', 1)
Gitlab::Cache::Import::Caching.increment_by('134940:increment_by', 1, timeout: 1)
# Wait 2 seconds...
Gitlab::Cache::Import::Caching.read('134940:increment_by') # => Will return `"2"` on this branch, but `nil` on master

Gitlab::Cache::Import::Caching.increment('134940:increment')
Gitlab::Cache::Import::Caching.increment('134940:increment', timeout: 1)
# Wait 2 seconds...
Gitlab::Cache::Import::Caching.increment('134940:increment') # => Will return `3` on this branch, but `1` on master

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Luke Duncalfe

Merge request reports