Class: Botomizer::Cache

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cache, prefix) ⇒ Cache

Returns a new instance of Cache.



4
5
6
7
# File 'lib/botomizer/cache.rb', line 4

def initialize(cache, prefix)
  @cache = cache
  @prefix = prefix
end

Instance Attribute Details

#prefixObject (readonly)

Returns the value of attribute prefix.



2
3
4
# File 'lib/botomizer/cache.rb', line 2

def prefix
  @prefix
end

Instance Method Details

#delete(key) ⇒ Object



17
18
19
# File 'lib/botomizer/cache.rb', line 17

def delete(key)
  @cache.delete("#{@prefix}_#{key}") if @cache
end

#exists?(key) ⇒ Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/botomizer/cache.rb', line 21

def exists?(key)
  @cache.exist?("#{@prefix}_#{key}")
end

#fetch(key) ⇒ Object



9
10
11
# File 'lib/botomizer/cache.rb', line 9

def fetch(key)
  @cache.fetch("#{@prefix}_#{key}") if @cache
end

#write(key, value) ⇒ Object



13
14
15
# File 'lib/botomizer/cache.rb', line 13

def write(key, value)
  @cache.write("#{@prefix}_#{key}", value, expires_in: 1.hour) if @cache
end