Class: Gitlab::Client::Cache::Caching

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/client/cache/caching.rb

Constant Summary collapse

PATH_PATTERN =
/^(..)(..)(.*)$/

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Caching

Returns a new instance of Caching.



10
11
12
# File 'lib/gitlab/client/cache/caching.rb', line 10

def initialize(config)
  @config = config
end

Instance Method Details

#cached(*args) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/gitlab/client/cache/caching.rb', line 14

def cached(*args)
  path = path_to(args)

  expires_in = determine_expires_in(args)

  return yield if expires_in == :skip_caching

  if path.exist? && path_fresh?(path, expires_in)
    load(path)
  else
    value = yield
    dump(path, value)
    value
  end
end