Class: Gitlab::Cache::JsonCache
- Inherits:
-
Object
- Object
- Gitlab::Cache::JsonCache
show all
- Defined in:
- lib/gitlab/cache/json_cache.rb
Constant Summary
collapse
- STRATEGY_KEY_COMPONENTS =
{
revision: Gitlab.revision,
version: [Gitlab::VERSION, Rails.version]
}.freeze
Instance Method Summary
collapse
Constructor Details
#initialize(options = {}) ⇒ JsonCache
Returns a new instance of JsonCache.
11
12
13
14
15
|
# File 'lib/gitlab/cache/json_cache.rb', line 11
def initialize(options = {})
@backend = options.fetch(:backend, Rails.cache)
@namespace = options.fetch(:namespace, nil)
@cache_key_strategy = options.fetch(:cache_key_strategy, :revision)
end
|
Instance Method Details
#active? ⇒ Boolean
17
18
19
20
21
22
23
|
# File 'lib/gitlab/cache/json_cache.rb', line 17
def active?
if backend.respond_to?(:active?)
backend.active?
else
true
end
end
|
#expire(key) ⇒ Object
25
26
27
|
# File 'lib/gitlab/cache/json_cache.rb', line 25
def expire(key)
backend.delete(cache_key(key))
end
|
#fetch(key, options = {}) ⇒ Object
39
40
41
42
43
44
45
46
47
48
49
50
|
# File 'lib/gitlab/cache/json_cache.rb', line 39
def fetch(key, options = {})
klass = options.delete(:as)
value = read(key, klass)
return value unless value.nil?
value = yield
write(key, value, options)
value
end
|
#read(key, klass = nil) ⇒ Object
29
30
31
32
33
|
# File 'lib/gitlab/cache/json_cache.rb', line 29
def read(key, klass = nil)
value = read_raw(key)
value = parse_value(value, klass) unless value.nil?
value
end
|
#write(key, value, options = nil) ⇒ Object
35
36
37
|
# File 'lib/gitlab/cache/json_cache.rb', line 35
def write(key, value, options = nil)
write_raw(key, value, options)
end
|