summaryrefslogtreecommitdiff
path: root/lib/repository_cache.rb
diff options
context:
space:
mode:
authorRobert Speicher <rspeicher@gmail.com>2015-01-28 23:08:28 -0500
committerRobert Speicher <rspeicher@gmail.com>2015-01-29 13:03:47 -0500
commit4eafc188437e0214c09d59083586ea871b625b14 (patch)
treeccd2fa1720f48ef7abe29fae603d3fa52dd67287 /lib/repository_cache.rb
parentd54f80980432d781b8730c672576e5e47620f502 (diff)
downloadgitlab-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/repository_cache.rb')
-rw-r--r--lib/repository_cache.rb25
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