Class: Lutaml::Model::CachedTypeResolver::ConcurrentMapCache Private

Inherits:
Object
  • Object
show all
Defined in:
lib/lutaml/model/cached_type_resolver/concurrent_map_cache.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Concurrent::Map-backed cache optimized for native Ruby runtimes.

The value block runs outside an atomic compute section so nested type resolution can re-enter the cache. Under concurrent misses, more than one thread may compute; the first stored value wins.

Instance Method Summary collapse

Constructor Details

#initialize(store: Concurrent::Map.new) ⇒ ConcurrentMapCache

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of ConcurrentMapCache.



14
15
16
# File 'lib/lutaml/model/cached_type_resolver/concurrent_map_cache.rb', line 14

def initialize(store: Concurrent::Map.new)
  @store = store
end

Instance Method Details

#clearObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



36
37
38
# File 'lib/lutaml/model/cached_type_resolver/concurrent_map_cache.rb', line 36

def clear
  @store.clear
end

#clear_context(context_id) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



30
31
32
33
34
# File 'lib/lutaml/model/cached_type_resolver/concurrent_map_cache.rb', line 30

def clear_context(context_id)
  @store.each_key do |key|
    @store.delete(key) if key[0] == context_id
  end
end

#fetch_or_store(cache_key) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



18
19
20
21
22
23
24
# File 'lib/lutaml/model/cached_type_resolver/concurrent_map_cache.rb', line 18

def fetch_or_store(cache_key)
  return @store[cache_key] if @store.key?(cache_key)

  value = yield
  @store.put_if_absent(cache_key, value)
  @store[cache_key]
end

#key?(cache_key) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


26
27
28
# File 'lib/lutaml/model/cached_type_resolver/concurrent_map_cache.rb', line 26

def key?(cache_key)
  @store.key?(cache_key)
end

#keysObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



40
41
42
# File 'lib/lutaml/model/cached_type_resolver/concurrent_map_cache.rb', line 40

def keys
  @store.keys
end