2015-01-28 23:08:28 -05:00
|
|
|
# Interface to the Redis-backed cache store used by the Repository model
|
|
|
|
class RepositoryCache
|
2015-01-30 10:17:55 -05:00
|
|
|
attr_reader :namespace, :backend
|
2015-01-28 23:08:28 -05:00
|
|
|
|
|
|
|
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
|
|
|
|
end
|