Commit c6f54ab1 authored by Stan Hu's avatar Stan Hu

Merge branch...

Merge branch '63513-ensure-gitlab-jsoncache-includes-the-gitlab-version-in-the-cache-key' into 'master'

Include the GitLab version in the cache key for Gitlab::JsonCache

See merge request gitlab-org/gitlab-ce!29938
parents eeb81259 1b7e7dde
---
title: Include the GitLab version in the cache key for Gitlab::JsonCache
merge_request: 29938
author:
type: fixed
......@@ -22,10 +22,10 @@ module Gitlab
expanded_cache_key = [namespace, key].compact
if cache_key_with_version
expanded_cache_key << Rails.version
expanded_cache_key << [Gitlab::VERSION, Rails.version]
end
expanded_cache_key.join(':')
expanded_cache_key.flatten.join(':').freeze
end
def expire(key)
......
......@@ -6,7 +6,7 @@ describe Gitlab::JsonCache do
let(:backend) { double('backend').as_null_object }
let(:namespace) { 'geo' }
let(:key) { 'foo' }
let(:expanded_key) { "#{namespace}:#{key}:#{Rails.version}" }
let(:expanded_key) { "#{namespace}:#{key}:#{Gitlab::VERSION}:#{Rails.version}" }
set(:broadcast_message) { create(:broadcast_message) }
subject(:cache) { described_class.new(namespace: namespace, backend: backend) }
......@@ -35,36 +35,39 @@ describe Gitlab::JsonCache do
describe '#cache_key' do
context 'when namespace is not defined' do
it 'expands out the key with Rails version' do
context 'when cache_key_with_version is true' do
it 'expands out the key with GitLab, and Rails versions' do
cache = described_class.new(cache_key_with_version: true)
cache_key = cache.cache_key(key)
expect(cache_key).to eq("#{key}:#{Rails.version}")
expect(cache_key).to eq("#{key}:#{Gitlab::VERSION}:#{Rails.version}")
end
end
context 'when cache_key_with_version is true' do
it 'expands out the key with namespace and Rails version' do
cache = described_class.new(namespace: namespace, cache_key_with_version: true)
context 'when cache_key_with_version is false' do
it 'returns the key' do
cache = described_class.new(namespace: nil, cache_key_with_version: false)
cache_key = cache.cache_key(key)
expect(cache_key).to eq("#{namespace}:#{key}:#{Rails.version}")
expect(cache_key).to eq(key)
end
end
end
context 'when cache_key_with_version is false' do
it 'expands out the key with namespace' do
cache = described_class.new(namespace: namespace, cache_key_with_version: false)
context 'when namespace is nil' do
context 'when cache_key_with_version is true' do
it 'expands out the key with GitLab, and Rails versions' do
cache = described_class.new(cache_key_with_version: true)
cache_key = cache.cache_key(key)
expect(cache_key).to eq("#{namespace}:#{key}")
expect(cache_key).to eq("#{key}:#{Gitlab::VERSION}:#{Rails.version}")
end
end
context 'when namespace is nil, and cache_key_with_version is false' do
context 'when cache_key_with_version is false' do
it 'returns the key' do
cache = described_class.new(namespace: nil, cache_key_with_version: false)
......@@ -75,6 +78,29 @@ describe Gitlab::JsonCache do
end
end
context 'when namespace is set' do
context 'when cache_key_with_version is true' do
it 'expands out the key with namespace and Rails version' do
cache = described_class.new(namespace: namespace, cache_key_with_version: true)
cache_key = cache.cache_key(key)
expect(cache_key).to eq("#{namespace}:#{key}:#{Gitlab::VERSION}:#{Rails.version}")
end
end
context 'when cache_key_with_version is false' do
it 'expands out the key with namespace' do
cache = described_class.new(namespace: namespace, cache_key_with_version: false)
cache_key = cache.cache_key(key)
expect(cache_key).to eq("#{namespace}:#{key}")
end
end
end
end
describe '#expire' do
it 'expires the given key from the cache' do
cache.expire(key)
......
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