Class: Librarian::Environment::RuntimeCache
- Inherits:
-
Object
- Object
- Librarian::Environment::RuntimeCache
- Defined in:
- lib/librarian/environment/runtime_cache.rb
Defined Under Namespace
Classes: KeyspaceCache
Instance Method Summary collapse
- #[](keyspace, key) ⇒ Object
- #[]=(keyspace, key, value) ⇒ Object
- #delete(keyspace, key) ⇒ Object
- #get(keyspace, key) ⇒ Object
- #include?(keyspace, key) ⇒ Boolean
-
#initialize ⇒ RuntimeCache
constructor
A new instance of RuntimeCache.
- #keyspace(keyspace) ⇒ Object
- #memo(keyspace, key) ⇒ Object
- #once(keyspace, key) ⇒ Object
- #put(keyspace, key, value = nil) ⇒ Object
Constructor Details
#initialize ⇒ RuntimeCache
Returns a new instance of RuntimeCache.
46 47 48 |
# File 'lib/librarian/environment/runtime_cache.rb', line 46 def initialize self.data = {} end |
Instance Method Details
#[](keyspace, key) ⇒ Object
75 76 77 |
# File 'lib/librarian/environment/runtime_cache.rb', line 75 def [](keyspace, key) get(keyspace, key) end |
#[]=(keyspace, key, value) ⇒ Object
79 80 81 |
# File 'lib/librarian/environment/runtime_cache.rb', line 79 def []=(keyspace, key, value) put(keyspace, key, value) end |
#delete(keyspace, key) ⇒ Object
62 63 64 |
# File 'lib/librarian/environment/runtime_cache.rb', line 62 def delete(keyspace, key) data.delete(combined_key(keyspace, key)) end |
#get(keyspace, key) ⇒ Object
54 55 56 |
# File 'lib/librarian/environment/runtime_cache.rb', line 54 def get(keyspace, key) data[combined_key(keyspace, key)] end |
#include?(keyspace, key) ⇒ Boolean
50 51 52 |
# File 'lib/librarian/environment/runtime_cache.rb', line 50 def include?(keyspace, key) data.include?(combined_key(keyspace, key)) end |
#keyspace(keyspace) ⇒ Object
83 84 85 |
# File 'lib/librarian/environment/runtime_cache.rb', line 83 def keyspace(keyspace) KeyspaceCache.new(self, keyspace) end |
#memo(keyspace, key) ⇒ Object
66 67 68 69 |
# File 'lib/librarian/environment/runtime_cache.rb', line 66 def memo(keyspace, key) put(keyspace, key, yield) unless include?(keyspace, key) get(keyspace, key) end |
#once(keyspace, key) ⇒ Object
71 72 73 |
# File 'lib/librarian/environment/runtime_cache.rb', line 71 def once(keyspace, key) memo(keyspace, key) { yield ; nil } end |
#put(keyspace, key, value = nil) ⇒ Object
58 59 60 |
# File 'lib/librarian/environment/runtime_cache.rb', line 58 def put(keyspace, key, value = nil) data[combined_key(keyspace, key)] = block_given? ? yield : value end |