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
0
Merge Requests
0
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
Jérome Perrin
gitlab-ce
Commits
76c9f071
Commit
76c9f071
authored
Jul 18, 2017
by
Lin Jen-Shin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update the comments for the new functionality
parent
aada5273
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
3 deletions
+19
-3
lib/gitlab/cache/request_store_wrap.rb
lib/gitlab/cache/request_store_wrap.rb
+19
-3
No files found.
lib/gitlab/cache/request_store_wrap.rb
View file @
76c9f071
...
@@ -2,7 +2,8 @@ module Gitlab
...
@@ -2,7 +2,8 @@ module Gitlab
module
Cache
module
Cache
# This module provides a simple way to cache values in RequestStore,
# This module provides a simple way to cache values in RequestStore,
# and the cache key would be based on the class name, method name,
# and the cache key would be based on the class name, method name,
# customized instance level values, and arguments.
# optionally customized instance level values, optionally customized
# method level values, and optional method arguments.
#
#
# A simple example:
# A simple example:
#
#
...
@@ -10,7 +11,7 @@ module Gitlab
...
@@ -10,7 +11,7 @@ module Gitlab
# extend Gitlab::Cache::RequestStoreWrap
# extend Gitlab::Cache::RequestStoreWrap
#
#
# request_store_wrap_key do
# request_store_wrap_key do
# [user
.id, project
.id]
# [user
&.id, project&
.id]
# end
# end
#
#
# request_store_wrap def can_push_to_branch?(ref)
# request_store_wrap def can_push_to_branch?(ref)
...
@@ -19,7 +20,22 @@ module Gitlab
...
@@ -19,7 +20,22 @@ module Gitlab
# end
# end
#
#
# This way, the result of `can_push_to_branch?` would be cached in
# This way, the result of `can_push_to_branch?` would be cached in
# `RequestStore.store` based on the cache key.
# `RequestStore.store` based on the cache key. If RequestStore is not
# currently active, then it would be stored in a hash saved in an
# instance variable, so the cache logic would be the same.
# Here's another example using customized method level values:
#
# class Commit
# extend Gitlab::Cache::RequestStoreWrap
#
# def author
# User.find_by_any_email(author_email.downcase)
# end
# request_store_wrap(:author) { author_email.downcase }
# end
#
# So that we could have different strategies for different methods
#
module
RequestStoreWrap
module
RequestStoreWrap
def
self
.
extended
(
klass
)
def
self
.
extended
(
klass
)
return
if
klass
<
self
return
if
klass
<
self
...
...
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