debian-mirror-gitlab/lib/repository_cache.rb

31 lines
616 B
Ruby
Raw Normal View History

2015-04-26 12:48:37 +05:30
# Interface to the Redis-backed cache store used by the Repository model
class RepositoryCache
2016-08-24 12:49:21 +05:30
attr_reader :namespace, :backend, :project_id
2015-04-26 12:48:37 +05:30
2016-08-24 12:49:21 +05:30
def initialize(namespace, project_id, backend = Rails.cache)
2015-04-26 12:48:37 +05:30
@namespace = namespace
@backend = backend
2016-08-24 12:49:21 +05:30
@project_id = project_id
2015-04-26 12:48:37 +05:30
end
def cache_key(type)
2016-08-24 12:49:21 +05:30
"#{type}:#{namespace}:#{project_id}"
2015-04-26 12:48:37 +05:30
end
def expire(key)
backend.delete(cache_key(key))
end
def fetch(key, &block)
backend.fetch(cache_key(key), &block)
end
2015-09-11 14:41:01 +05:30
def exist?(key)
backend.exist?(cache_key(key))
end
def read(key)
backend.read(cache_key(key))
end
2015-04-26 12:48:37 +05:30
end