BigW Consortium Gitlab

repository_cache.rb 548 Bytes
Newer Older
1 2
# Interface to the Redis-backed cache store used by the Repository model
class RepositoryCache
3
  attr_reader :namespace, :backend
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20

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

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

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

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

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

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