Class: ActiveMatrix::Memory::Base
- Inherits:
-
Object
- Object
- ActiveMatrix::Memory::Base
- Includes:
- Logging
- Defined in:
- lib/active_matrix/memory/base.rb
Overview
Base class for memory implementations
Direct Known Subclasses
Instance Method Summary collapse
-
#clear! ⇒ Object
Clear all memory (use with caution).
-
#delete(key) ⇒ Object
Delete a key.
-
#exists?(key) ⇒ Boolean
Check if a key exists.
-
#get(key) ⇒ Object
Get a value from memory.
-
#get_multi(*keys) ⇒ Object
Get multiple keys at once.
-
#initialize ⇒ Base
constructor
A new instance of Base.
-
#set(key, value, expires_in: nil) ⇒ Object
Set a value in memory.
-
#set_multi(hash, expires_in: nil) ⇒ Object
Set multiple keys at once.
Methods included from Logging
Constructor Details
#initialize ⇒ Base
Returns a new instance of Base.
9 10 11 |
# File 'lib/active_matrix/memory/base.rb', line 9 def initialize @cache_enabled = Rails.cache.present? rescue false end |
Instance Method Details
#clear! ⇒ Object
Clear all memory (use with caution)
44 45 46 |
# File 'lib/active_matrix/memory/base.rb', line 44 def clear! raise NotImplementedError end |
#delete(key) ⇒ Object
Delete a key
29 30 31 |
# File 'lib/active_matrix/memory/base.rb', line 29 def delete(key) raise NotImplementedError end |
#exists?(key) ⇒ Boolean
Check if a key exists
24 25 26 |
# File 'lib/active_matrix/memory/base.rb', line 24 def exists?(key) raise NotImplementedError end |
#get(key) ⇒ Object
Get a value from memory
14 15 16 |
# File 'lib/active_matrix/memory/base.rb', line 14 def get(key) raise NotImplementedError end |
#get_multi(*keys) ⇒ Object
Get multiple keys at once
34 35 36 |
# File 'lib/active_matrix/memory/base.rb', line 34 def get_multi(*keys) keys.index_with { |key| get(key) } end |
#set(key, value, expires_in: nil) ⇒ Object
Set a value in memory
19 20 21 |
# File 'lib/active_matrix/memory/base.rb', line 19 def set(key, value, expires_in: nil) raise NotImplementedError end |
#set_multi(hash, expires_in: nil) ⇒ Object
Set multiple keys at once
39 40 41 |
# File 'lib/active_matrix/memory/base.rb', line 39 def set_multi(hash, expires_in: nil) hash.each { |key, value| set(key, value, expires_in: expires_in) } end |