Commit 16eaca0f authored by Stan Hu's avatar Stan Hu

Merge branch '12374-use-safe-request-store-without-json-cache' into 'master'

Geo - Use Gitlab::JsonCache only for the persistent cache on Gitlab::Geo

Closes #12374

See merge request gitlab-org/gitlab-ee!14378
parents ff589296 b87b6780
......@@ -86,24 +86,24 @@ module Gitlab
end
def self.request_store_cache
@request_store_cache ||= Gitlab::JsonCache.new(namespace: :geo, backend: Gitlab::SafeRequestStore)
Gitlab::SafeRequestStore
end
def self.cache_value(key, as: nil, &block)
def self.cache_value(raw_key, as: nil, &block)
return yield unless request_store_cache.active?
request_store_cache.fetch(key, as: as) do
request_store_cache.fetch(cache.cache_key(raw_key)) do
# We need a short expire time as we can't manually expire on a secondary node
cache.fetch(key, as: as, expires_in: 15.seconds) { yield }
cache.fetch(raw_key, as: as, expires_in: 15.seconds) { yield }
end
end
def self.expire_cache!
return true unless request_store_cache.active?
CACHE_KEYS.each do |key|
cache.expire(key)
request_store_cache.expire(key)
CACHE_KEYS.each do |raw_key|
cache.expire(raw_key)
request_store_cache.delete(cache.cache_key(raw_key))
end
true
......
......@@ -9,8 +9,12 @@ describe Gitlab::Geo, :geo, :request_store do
shared_examples 'a Geo cached value' do |method, key|
it 'includes GitLab version and Rails.version in the cache key' do
expanded_key = "geo:#{key}:#{Gitlab::VERSION}:#{Rails.version}"
expect(Gitlab::SafeRequestStore).to receive(:fetch)
.with(expanded_key).and_call_original
expect(Rails.cache).to receive(:write)
.with("geo:#{key}:#{Gitlab::VERSION}:#{Rails.version}", an_instance_of(String), expires_in: 15.seconds)
.with(expanded_key, an_instance_of(String), expires_in: 15.seconds)
described_class.public_send(method)
end
......@@ -171,7 +175,10 @@ describe Gitlab::Geo, :geo, :request_store do
describe '.expire_cache!' do
it 'clears the Geo cache keys', :request_store do
described_class::CACHE_KEYS.each do |raw_key|
expect(Rails.cache).to receive(:delete).with("geo:#{raw_key}:#{Gitlab::VERSION}:#{Rails.version}")
expanded_key = "geo:#{raw_key}:#{Gitlab::VERSION}:#{Rails.version}"
expect(Rails.cache).to receive(:delete).with(expanded_key)
expect(Gitlab::SafeRequestStore).to receive(:delete).with(expanded_key)
end
described_class.expire_cache!
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment