Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
94d9e335
Commit
94d9e335
authored
Jun 21, 2019
by
Douglas Barbosa Alexandre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Include the GitLab version in the cache key for Gitlab::JsonCache
parent
d0a921b4
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
49 additions
and
23 deletions
+49
-23
lib/gitlab/json_cache.rb
lib/gitlab/json_cache.rb
+2
-2
spec/lib/gitlab/json_cache_spec.rb
spec/lib/gitlab/json_cache_spec.rb
+47
-21
No files found.
lib/gitlab/json_cache.rb
View file @
94d9e335
...
...
@@ -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
)
...
...
spec/lib/gitlab/json_cache_spec.rb
View file @
94d9e335
...
...
@@ -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,42 +35,68 @@ describe Gitlab::JsonCache do
describe
'#cache_key'
do
context
'when namespace is not defined'
do
it
'expands out the key with Rails version'
do
cache
=
described_class
.
new
(
cache_key_with_version:
true
)
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
)
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
end
context
'when cache_key_with_version is tru
e'
do
it
'expands out the key with namespace and Rails version
'
do
cache
=
described_class
.
new
(
namespace:
namespace
,
cache_key_with_version:
tru
e
)
context
'when cache_key_with_version is fals
e'
do
it
'returns the key
'
do
cache
=
described_class
.
new
(
namespace:
nil
,
cache_key_with_version:
fals
e
)
cache_key
=
cache
.
cache_key
(
key
)
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
)
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 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
(
key
)
end
end
end
context
'when namespace is nil, and cache_key_with_version is false'
do
it
'returns the key'
do
cache
=
described_class
.
new
(
namespace:
nil
,
cache_key_with_version:
false
)
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
)
cache_key
=
cache
.
cache_key
(
key
)
expect
(
cache_key
).
to
eq
(
"
#{
namespace
}
:
#{
key
}
:
#{
Gitlab
::
VERSION
}
:
#{
Rails
.
version
}
"
)
end
end
expect
(
cache_key
).
to
eq
(
key
)
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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment