2015-01-28 23:08:28 -05:00
|
|
|
# Interface to the Redis-backed cache store used by the Repository model
|
|
|
|
class RepositoryCache
|
2016-07-24 13:39:28 -04:00
|
|
|
attr_reader :namespace, :backend, :project_id
|
2015-01-28 23:08:28 -05:00
|
|
|
|
2016-07-24 13:39:28 -04:00
|
|
|
def initialize(namespace, project_id, backend = Rails.cache)
|
2015-01-28 23:08:28 -05:00
|
|
|
@namespace = namespace
|
|
|
|
@backend = backend
|
2016-07-24 13:39:28 -04:00
|
|
|
@project_id = project_id
|
2015-01-28 23:08:28 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def cache_key(type)
|
2016-07-24 13:39:28 -04:00
|
|
|
"#{type}:#{namespace}:#{project_id}"
|
2015-01-28 23:08:28 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def expire(key)
|
|
|
|
backend.delete(cache_key(key))
|
|
|
|
end
|
|
|
|
|
|
|
|
def fetch(key, &block)
|
|
|
|
backend.fetch(cache_key(key), &block)
|
|
|
|
end
|
2015-07-17 08:50:03 -04:00
|
|
|
|
|
|
|
def exist?(key)
|
2015-07-17 09:22:56 -04:00
|
|
|
backend.exist?(cache_key(key))
|
|
|
|
end
|
|
|
|
|
|
|
|
def read(key)
|
|
|
|
backend.read(cache_key(key))
|
2015-07-17 08:50:03 -04:00
|
|
|
end
|
2015-01-28 23:08:28 -05:00
|
|
|
end
|