Module: Gitlab::SafeRequestStore

Defined in:
lib/gitlab/safe_request_store.rb

Constant Summary collapse

NULL_STORE =
Gitlab::NullRequestStore.new

Class Method Summary collapse

Class Method Details

.delete_if(&block) ⇒ Object


40
41
42
43
44
# File 'lib/gitlab/safe_request_store.rb', line 40

def self.delete_if(&block)
  return unless RequestStore.active?

  storage.delete_if { |k, v| block.call(k) }
end

.storageObject

Access to the backing storage of the request store. This returns an object with `[]` and `[]=` methods that does not discard values.

This can be useful if storage is needed for a delimited purpose, and the forgetful nature of the null store is undesirable.


28
29
30
# File 'lib/gitlab/safe_request_store.rb', line 28

def self.storage
  store.store
end

.storeObject


15
16
17
18
19
20
21
# File 'lib/gitlab/safe_request_store.rb', line 15

def self.store
  if RequestStore.active?
    RequestStore
  else
    NULL_STORE
  end
end

.write(key, value, options = nil) ⇒ Object

This method accept an options hash to be compatible with ActiveSupport::Cache::Store#write method. The options are not passed to the underlying cache implementation because RequestStore#write accepts only a key, and value params.


36
37
38
# File 'lib/gitlab/safe_request_store.rb', line 36

def self.write(key, value, options = nil)
  store.write(key, value)
end