Class: BasicCache::Store

Inherits:
Object
  • Object
show all
Defined in:
lib/basiccache/stores/store.rb

Overview

Basic store object (uses a Hash)

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#rawObject (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

Returns:

  • (Boolean)


45
46
47
# File 'lib/basiccache/stores/store.rb', line 45

def include?(key)
  @raw.include? key
end

#keysObject

Array of keys in the store



52
53
54
# File 'lib/basiccache/stores/store.rb', line 52

def keys
  @raw.keys
end

#sizeObject

Return the size of the store



38
39
40
# File 'lib/basiccache/stores/store.rb', line 38

def size
  @raw.size
end