Class: Librarian::Environment::RuntimeCache

Inherits:
Object
  • Object
show all
Defined in:
lib/librarian/environment/runtime_cache.rb

Defined Under Namespace

Classes: KeyspaceCache

Instance Method Summary collapse

Constructor Details

#initializeRuntimeCache

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

Returns:

  • (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