summaryrefslogtreecommitdiff
path: root/lib/repository_cache.rb
blob: 068a95790c0a61f2da7372f28bc89b18a0774d0a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# Interface to the Redis-backed cache store used by the Repository model
class RepositoryCache
  attr_reader :namespace, :backend, :project_id

  def initialize(namespace, project_id, backend = Rails.cache)
    @namespace = namespace
    @backend = backend
    @project_id = project_id
  end

  def cache_key(type)
    "#{type}:#{namespace}:#{project_id}"
  end

  def expire(key)
    backend.delete(cache_key(key))
  end

  def fetch(key, &block)
    backend.fetch(cache_key(key), &block)
  end

  def exist?(key)
    backend.exist?(cache_key(key))
  end

  def read(key)
    backend.read(cache_key(key))
  end
end