Class: BasicCache::Store
- Inherits:
-
Object
- Object
- BasicCache::Store
- Defined in:
- lib/basiccache/stores/store.rb
Overview
Basic store object (uses a Hash)
Instance Attribute Summary collapse
-
#raw ⇒ Object
readonly
Returns the value of attribute raw.
Instance Method Summary collapse
-
#[](key) ⇒ Object
Retrieve a key.
-
#[]=(key, value) ⇒ Object
Set a key.
-
#clear!(key = nil) ⇒ Object
Clears a specified key or the whole store.
-
#include?(key) ⇒ Boolean
Check for a key in the store.
-
#initialize(_ = {}) ⇒ Store
constructor
Generate an empty store.
-
#keys ⇒ Object
Array of keys in the store.
-
#size ⇒ Object
Return the size of the store.
Constructor Details
#initialize(_ = {}) ⇒ Store
Generate an empty store
10 11 12 |
# File 'lib/basiccache/stores/store.rb', line 10 def initialize(_ = {}) @raw = {} end |
Instance Attribute Details
#raw ⇒ Object (readonly)
Returns the value of attribute raw.
5 6 7 |
# File 'lib/basiccache/stores/store.rb', line 5 def raw @raw end |
Instance Method Details
#[](key) ⇒ Object
Retrieve a key
24 25 26 |
# File 'lib/basiccache/stores/store.rb', line 24 def [](key) @raw[key] end |
#[]=(key, value) ⇒ Object
Set a key
31 32 33 |
# File 'lib/basiccache/stores/store.rb', line 31 def []=(key, value) @raw[key] = value end |
#clear!(key = nil) ⇒ Object
Clears a specified key or the whole store
17 18 19 |
# File 'lib/basiccache/stores/store.rb', line 17 def clear!(key = nil) key.nil? ? @raw.clear : @raw.delete(key) end |
#include?(key) ⇒ Boolean
Check for a key in the store
45 46 47 |
# File 'lib/basiccache/stores/store.rb', line 45 def include?(key) @raw.include? key end |
#keys ⇒ Object
Array of keys in the store
52 53 54 |
# File 'lib/basiccache/stores/store.rb', line 52 def keys @raw.keys end |
#size ⇒ Object
Return the size of the store
38 39 40 |
# File 'lib/basiccache/stores/store.rb', line 38 def size @raw.size end |