Class: Botomizer::Cache
- Inherits:
-
Object
- Object
- Botomizer::Cache
- Defined in:
- lib/botomizer/cache.rb
Instance Attribute Summary collapse
-
#prefix ⇒ Object
readonly
Returns the value of attribute prefix.
Instance Method Summary collapse
- #delete(key) ⇒ Object
- #exists?(key) ⇒ Boolean
- #fetch(key) ⇒ Object
-
#initialize(cache, prefix) ⇒ Cache
constructor
A new instance of Cache.
- #write(key, value) ⇒ Object
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
#prefix ⇒ Object (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
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 |