class Lutaml::Model::OneEntryCache
hash allocation for the common case of a single repeated key.
When the key changes, the old entry is replaced. This avoids
is queried repeatedly for all rules of a given element.
Used for MappingRule#namespaced_names where the same parent_namespace
A single-entry cache that stores one key-value pair at a time.
def clear
def clear @key = nil @value = nil @filled = false end
def empty?
def empty? !@filled end
def fetch(key)
Returns the cached value if key matches, nil otherwise.
def fetch(key) return nil unless @filled return @value if @key == key nil end
def fetch_or_compute(key)
def fetch_or_compute(key) cached = fetch(key) return cached unless cached.nil? value = yield store(key, value) value end
def initialize
def initialize @key = nil @value = nil @filled = false end
def store(key, value)
def store(key, value) @key = key @value = value @filled = true value end