Class: Persistent::Cache
- Inherits:
-
Object
- Object
- Persistent::Cache
- Defined in:
- lib/persistent-cache.rb,
lib/persistent-cache/version.rb
Constant Summary collapse
- STORAGE_RAM =
'ram'- FRESH =
Fresh is 1 day less than the bacula default job retention time. If this is configured differently, FRESH should be updated as well.
15465600- VERSION =
"0.4.3"
Instance Attribute Summary collapse
-
#encoding ⇒ Object
Returns the value of attribute encoding.
-
#fresh ⇒ Object
Returns the value of attribute fresh.
-
#storage ⇒ Object
Returns the value of attribute storage.
-
#storage_details ⇒ Object
Returns the value of attribute storage_details.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
- #clear ⇒ Object
- #each(&_block) ⇒ Object
-
#initialize(storage_details, fresh = FRESH, storage = STORAGE_RAM) ⇒ Cache
constructor
A new instance of Cache.
- #key?(key) ⇒ Boolean
- #keys ⇒ Object
- #set(key, value, timestamp) ⇒ Object
- #size ⇒ Object
- #timestamp?(key) ⇒ Boolean
Constructor Details
#initialize(storage_details, fresh = FRESH, storage = STORAGE_RAM) ⇒ Cache
Returns a new instance of Cache.
17 18 19 20 21 22 23 24 25 |
# File 'lib/persistent-cache.rb', line 17 def initialize(storage_details, fresh = FRESH, storage = STORAGE_RAM) raise ArgumentError.new("No storage details provided") if storage_details.nil? or storage_details == "" @storage = StorageRAM.new if storage == STORAGE_RAM @fresh = fresh @storage_details = storage_details raise ArgumentError.new("Unsupported storage type #{storage}}") if @storage.nil? end |
Instance Attribute Details
#encoding ⇒ Object
Returns the value of attribute encoding.
15 16 17 |
# File 'lib/persistent-cache.rb', line 15 def encoding @encoding end |
#fresh ⇒ Object
Returns the value of attribute fresh.
14 15 16 |
# File 'lib/persistent-cache.rb', line 14 def fresh @fresh end |
#storage ⇒ Object
Returns the value of attribute storage.
13 14 15 |
# File 'lib/persistent-cache.rb', line 13 def storage @storage end |
#storage_details ⇒ Object
Returns the value of attribute storage_details.
12 13 14 |
# File 'lib/persistent-cache.rb', line 12 def storage_details @storage_details end |
Instance Method Details
#[](key) ⇒ Object
43 44 45 |
# File 'lib/persistent-cache.rb', line 43 def [](key) lookup_key(key) end |
#[]=(key, value) ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/persistent-cache.rb', line 35 def []=(key, value) if value.nil? delete_entry(key) else save_key_value_pair(key, value) end end |
#clear ⇒ Object
61 62 63 |
# File 'lib/persistent-cache.rb', line 61 def clear @storage.clear end |
#each(&_block) ⇒ Object
47 48 49 50 51 |
# File 'lib/persistent-cache.rb', line 47 def each(&_block) keys.each do |key| yield key, lookup_key(key) end end |
#key?(key) ⇒ Boolean
72 73 74 75 76 77 78 79 |
# File 'lib/persistent-cache.rb', line 72 def key?(key) if @storage.keys and @storage.keys[0] @storage.keys[0].each do |k| return k if k == key end end return nil end |
#keys ⇒ Object
57 58 59 |
# File 'lib/persistent-cache.rb', line 57 def keys @storage.keys end |
#set(key, value, timestamp) ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/persistent-cache.rb', line 27 def set(key, value, ) if value.nil? delete_entry(key) else save_key_value_pair(key, value, ) end end |
#size ⇒ Object
53 54 55 |
# File 'lib/persistent-cache.rb', line 53 def size @storage.size end |
#timestamp?(key) ⇒ Boolean
65 66 67 68 69 70 |
# File 'lib/persistent-cache.rb', line 65 def (key) k = encode_if_requested(key) result = @storage.lookup_key(k) return nil if result.nil? or result[1].nil? Time.parse(result[1]) end |