Class: Lutaml::Model::CachedTypeResolver::MutexHashCache Private
- Inherits:
-
Object
- Object
- Lutaml::Model::CachedTypeResolver::MutexHashCache
- Defined in:
- lib/lutaml/model/cached_type_resolver/mutex_hash_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.
Hash-backed cache that only relies on Mutex semantics available on Opal.
Instance Method Summary collapse
- #clear ⇒ Object private
- #clear_context(context_id) ⇒ Object private
- #fetch_or_store(cache_key) ⇒ Object private
-
#initialize(store: {}, mutex: Mutex.new) ⇒ MutexHashCache
constructor
private
A new instance of MutexHashCache.
- #key?(cache_key) ⇒ Boolean private
- #keys ⇒ Object private
Constructor Details
#initialize(store: {}, mutex: Mutex.new) ⇒ MutexHashCache
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 MutexHashCache.
8 9 10 11 |
# File 'lib/lutaml/model/cached_type_resolver/mutex_hash_cache.rb', line 8 def initialize(store: {}, mutex: Mutex.new) @store = store @mutex = mutex end |
Instance Method Details
#clear ⇒ 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.
41 42 43 |
# File 'lib/lutaml/model/cached_type_resolver/mutex_hash_cache.rb', line 41 def clear @mutex.synchronize { @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.
35 36 37 38 39 |
# File 'lib/lutaml/model/cached_type_resolver/mutex_hash_cache.rb', line 35 def clear_context(context_id) @mutex.synchronize do @store.delete_if { |key, _| 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.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/lutaml/model/cached_type_resolver/mutex_hash_cache.rb', line 13 def fetch_or_store(cache_key) found = false cached_value = @mutex.synchronize do if @store.key?(cache_key) found = true @store[cache_key] end end return cached_value if found value = yield @mutex.synchronize do @store[cache_key] = value unless @store.key?(cache_key) @store[cache_key] end 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.
31 32 33 |
# File 'lib/lutaml/model/cached_type_resolver/mutex_hash_cache.rb', line 31 def key?(cache_key) @mutex.synchronize { @store.key?(cache_key) } end |
#keys ⇒ 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.
45 46 47 |
# File 'lib/lutaml/model/cached_type_resolver/mutex_hash_cache.rb', line 45 def keys @mutex.synchronize { @store.keys.dup } end |