summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLin Jen-Shin <godfat@godfat.org>2017-07-18 01:30:58 +0800
committerLin Jen-Shin <godfat@godfat.org>2017-07-18 01:30:58 +0800
commit76c9f071db66e56714908cd46dcdb25c3e998766 (patch)
tree7df952f7d000b01d1353228c26cc52f4892ccc01
parentaada5273fa260cbd2441e8f1a0c95d951b4977fc (diff)
downloadgitlab-ce-76c9f071db66e56714908cd46dcdb25c3e998766.tar.gz
Update the comments for the new functionality
-rw-r--r--lib/gitlab/cache/request_store_wrap.rb22
1 files changed, 19 insertions, 3 deletions
diff --git a/lib/gitlab/cache/request_store_wrap.rb b/lib/gitlab/cache/request_store_wrap.rb
index 1cb442444bb..e10ff235934 100644
--- a/lib/gitlab/cache/request_store_wrap.rb
+++ b/lib/gitlab/cache/request_store_wrap.rb
@@ -2,7 +2,8 @@ module Gitlab
module Cache
# This module provides a simple way to cache values in RequestStore,
# 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:
#
@@ -10,7 +11,7 @@ module Gitlab
# extend Gitlab::Cache::RequestStoreWrap
#
# request_store_wrap_key do
- # [user.id, project.id]
+ # [user&.id, project&.id]
# end
#
# request_store_wrap def can_push_to_branch?(ref)
@@ -19,7 +20,22 @@ module Gitlab
# end
#
# 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
def self.extended(klass)
return if klass < self