summaryrefslogtreecommitdiff
path: root/lib/repository_cache.rb
blob: 0d52f50be91caf5059868ddfb8be798b39a1572e (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
# Interface to the Redis-backed cache store used by the Repository model
class RepositoryCache
  attr_reader :namespace

  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

  private

  attr_reader :backend
end