Commit 76c9f071 authored by Lin Jen-Shin's avatar Lin Jen-Shin

Update the comments for the new functionality

parent aada5273
......@@ -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
......
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