diff options
author | Robert Speicher <rspeicher@gmail.com> | 2015-01-28 23:08:28 -0500 |
---|---|---|
committer | Robert Speicher <rspeicher@gmail.com> | 2015-01-29 13:03:47 -0500 |
commit | 4eafc188437e0214c09d59083586ea871b625b14 (patch) | |
tree | ccd2fa1720f48ef7abe29fae603d3fa52dd67287 /lib | |
parent | d54f80980432d781b8730c672576e5e47620f502 (diff) | |
download | gitlab-ce-4eafc188437e0214c09d59083586ea871b625b14.tar.gz |
Refactor Repository to use new RepositoryCache class
Abstracts away the lower-level implementation details from the
Repository model.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/repository_cache.rb | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/lib/repository_cache.rb b/lib/repository_cache.rb new file mode 100644 index 00000000000..0d52f50be91 --- /dev/null +++ b/lib/repository_cache.rb @@ -0,0 +1,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 |