BigW Consortium Gitlab

repository_cache.rb 616 Bytes
Newer Older
1 2
# Interface to the Redis-backed cache store used by the Repository model
class RepositoryCache
3
  attr_reader :namespace, :backend, :project_id
4

5
  def initialize(namespace, project_id, backend = Rails.cache)
6 7
    @namespace = namespace
    @backend = backend
8
    @project_id = project_id
9 10 11
  end

  def cache_key(type)
12
    "#{type}:#{namespace}:#{project_id}"
13 14 15 16 17 18 19 20 21
  end

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

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

  def exist?(key)
24 25 26 27 28
    backend.exist?(cache_key(key))
  end

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