Class: Elephas::Providers::Hash
- Inherits:
-
Object
- Object
- Elephas::Providers::Hash
- Includes:
- Base
- Defined in:
- lib/elephas/providers/hash.rb
Overview
This is a simple providers, which uses an hash for storing the values.
Instance Attribute Summary (collapse)
-
- (Object) data
The internal hash used by the provider.
Instance Method Summary (collapse)
-
- (Boolean) delete(key)
Deletes a value from the cache.
-
- (Boolean) exists?(key)
Checks if a key exists in the cache.
-
- (Hash) initialize(data = nil)
constructor
Initialize the provider.
-
- (Entry|NilClass) read(key)
Reads a value from the cache.
-
- (Object) write(key, value, options = {})
Writes a value to the cache.
Methods included from Base
Constructor Details
- (Hash) initialize(data = nil)
Initialize the provider
18 19 20 21 |
# File 'lib/elephas/providers/hash.rb', line 18 def initialize(data = nil) data = {} if !data || !data.is_a?(::Hash) @data = data end |
Instance Attribute Details
- (Object) data
The internal hash used by the provider.
14 15 16 |
# File 'lib/elephas/providers/hash.rb', line 14 def data @data end |
Instance Method Details
- (Boolean) delete(key)
Deletes a value from the cache.
49 50 51 52 53 54 |
# File 'lib/elephas/providers/hash.rb', line 49 def delete(key) fkey = key.ensure_string rv = @data.has_key?(fkey) @data.delete(fkey) rv end |
- (Boolean) exists?(key)
Checks if a key exists in the cache.
60 61 62 63 |
# File 'lib/elephas/providers/hash.rb', line 60 def exists?(key) fkey = key.ensure_string @data.has_key?(fkey) && @data[fkey].valid? end |
- (Entry|NilClass) read(key)
Reads a value from the cache.
27 28 29 |
# File 'lib/elephas/providers/hash.rb', line 27 def read(key) self.exists?(key) ? @data[key.ensure_string] : nil end |
- (Object) write(key, value, options = {})
Writes a value to the cache.
38 39 40 41 42 43 |
# File 'lib/elephas/providers/hash.rb', line 38 def write(key, value, = {}) fvalue = ::Elephas::Entry.ensure(value, key, ) fvalue.refresh @data[key.ensure_string] = fvalue value end |