Class: Gitlab::Metrics::Dashboard::Cache

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/metrics/dashboard/cache.rb

Constant Summary collapse

CACHE_KEYS =
'all_cached_metric_dashboards'

Instance Method Summary collapse

Constructor Details

#initialize(project) ⇒ Cache

Returns a new instance of Cache.


20
21
22
# File 'lib/gitlab/metrics/dashboard/cache.rb', line 20

def initialize(project)
  @project = project
end

Instance Method Details

#delete_all!Object

Resets all dashboard caches, such that all dashboard content will be loaded from source on subsequent dashboard calls.


35
36
37
38
39
# File 'lib/gitlab/metrics/dashboard/cache.rb', line 35

def delete_all!
  all_keys.each { |key| Rails.cache.delete(key) }

  Rails.cache.delete(catalog_key)
end

#fetch(key) ⇒ Object

Stores a dashboard in the cache, documenting the key so the cache can be cleared in bulk at another time.


26
27
28
29
30
# File 'lib/gitlab/metrics/dashboard/cache.rb', line 26

def fetch(key)
  register_key(key)

  Rails.cache.fetch(key) { yield }
end