Class: RepositoryCache

Inherits:
Object
  • Object
show all
Defined in:
lib/repository_cache.rb

Overview

Interface to the Redis-backed cache store used by the Repository model

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(namespace, backend = Rails.cache) ⇒ RepositoryCache

Returns a new instance of RepositoryCache


5
6
7
8
# File 'lib/repository_cache.rb', line 5

def initialize(namespace, backend = Rails.cache)
  @namespace = namespace
  @backend = backend
end

Instance Attribute Details

#backendObject (readonly)

Returns the value of attribute backend


3
4
5
# File 'lib/repository_cache.rb', line 3

def backend
  @backend
end

#namespaceObject (readonly)

Returns the value of attribute namespace


3
4
5
# File 'lib/repository_cache.rb', line 3

def namespace
  @namespace
end

Instance Method Details

#cache_key(type) ⇒ Object


10
11
12
# File 'lib/repository_cache.rb', line 10

def cache_key(type)
  "#{type}:#{namespace}"
end

#exist?(key) ⇒ Boolean

Returns:

  • (Boolean)

22
23
24
# File 'lib/repository_cache.rb', line 22

def exist?(key)
  backend.exist?(cache_key(key))
end

#expire(key) ⇒ Object


14
15
16
# File 'lib/repository_cache.rb', line 14

def expire(key)
  backend.delete(cache_key(key))
end

#fetch(key, &block) ⇒ Object


18
19
20
# File 'lib/repository_cache.rb', line 18

def fetch(key, &block)
  backend.fetch(cache_key(key), &block)
end

#read(key) ⇒ Object


26
27
28
# File 'lib/repository_cache.rb', line 26

def read(key)
  backend.read(cache_key(key))
end