Class: Lutaml::Model::CachedTypeResolver Private
- Inherits:
-
Object
- Object
- Lutaml::Model::CachedTypeResolver
- Defined in:
- lib/lutaml/model/cached_type_resolver.rb,
lib/lutaml/model/cached_type_resolver/mutex_hash_cache.rb,
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.
CachedTypeResolver adds caching to any TypeResolver using the Decorator pattern.
This is an INTERNAL class. Users should use Register and GlobalRegister.
Responsibility: Add caching to type resolution
This class:
-
Decorates any TypeResolver-like object (duck typing)
-
Uses a runtime-selected cache backend
-
Centralized cache management - ONE place to clear ALL type caches
Defined Under Namespace
Classes: ConcurrentMapCache, MutexHashCache
Instance Attribute Summary collapse
-
#cache_backend ⇒ Object
readonly
private
The delegate resolver (typically TypeResolver).
-
#delegate ⇒ Object
readonly
private
The delegate resolver (typically TypeResolver).
Class Method Summary collapse
- .default_cache_backend ⇒ Object private
Instance Method Summary collapse
-
#cache_stats ⇒ Hash
private
Get cache statistics (useful for debugging/monitoring).
-
#clear_all_caches ⇒ void
private
Clear all caches.
-
#clear_cache(context_id) ⇒ void
private
Clear the cache for a specific context.
-
#initialize(delegate:, cache_backend: self.class.default_cache_backend) ⇒ CachedTypeResolver
constructor
private
Create a new CachedTypeResolver.
-
#resolvable?(name, context) ⇒ Boolean
private
Check if a type can be resolved, using cache if available.
-
#resolve(name, context) ⇒ Class
private
Resolve a type name to a class, using cache if available.
-
#resolve_or_nil(name, context) ⇒ Class?
private
Try to resolve a type, returning nil if not found.
Constructor Details
#initialize(delegate:, cache_backend: self.class.default_cache_backend) ⇒ CachedTypeResolver
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.
Create a new CachedTypeResolver.
51 52 53 54 |
# File 'lib/lutaml/model/cached_type_resolver.rb', line 51 def initialize(delegate:, cache_backend: self.class.default_cache_backend) @delegate = delegate @cache_backend = cache_backend end |
Instance Attribute Details
#cache_backend ⇒ Object (readonly)
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 The delegate resolver (typically TypeResolver).
36 37 38 |
# File 'lib/lutaml/model/cached_type_resolver.rb', line 36 def cache_backend @cache_backend end |
#delegate ⇒ Object (readonly)
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 The delegate resolver (typically TypeResolver).
36 37 38 |
# File 'lib/lutaml/model/cached_type_resolver.rb', line 36 def delegate @delegate end |
Class Method Details
.default_cache_backend ⇒ 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.
38 39 40 41 42 43 44 |
# File 'lib/lutaml/model/cached_type_resolver.rb', line 38 def self.default_cache_backend if RuntimeCompatibility.opal? MutexHashCache.new else ConcurrentMapCache.new end end |
Instance Method Details
#cache_stats ⇒ Hash
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.
Get cache statistics (useful for debugging/monitoring).
122 123 124 125 126 127 128 129 |
# File 'lib/lutaml/model/cached_type_resolver.rb', line 122 def cache_stats keys = @cache_backend.keys { size: keys.size, keys: keys, } end |
#clear_all_caches ⇒ void
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.
This method returns an undefined value.
Clear all caches.
115 116 117 |
# File 'lib/lutaml/model/cached_type_resolver.rb', line 115 def clear_all_caches @cache_backend.clear end |
#clear_cache(context_id) ⇒ void
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.
This method returns an undefined value.
Clear the cache for a specific context.
108 109 110 |
# File 'lib/lutaml/model/cached_type_resolver.rb', line 108 def clear_cache(context_id) @cache_backend.clear_context(context_id) end |
#resolvable?(name, context) ⇒ 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.
Check if a type can be resolved, using cache if available.
81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/lutaml/model/cached_type_resolver.rb', line 81 def resolvable?(name, context) return true if name.is_a?(Class) cache_key = build_cache_key(name, context) # Check cache first (fast path) return true if @cache_backend.key?(cache_key) # Not in cache - delegate @delegate.resolvable?(name, context) end |
#resolve(name, context) ⇒ Class
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.
Resolve a type name to a class, using cache if available.
Cache backends synchronize storage, but compute outside exclusive cache updates so recursive type resolution can populate related keys.
65 66 67 68 69 70 71 72 73 74 |
# File 'lib/lutaml/model/cached_type_resolver.rb', line 65 def resolve(name, context) # Fast path: Class types are passed through directly (no caching needed) return @delegate.resolve(name, context) if name.is_a?(Class) cache_key = build_cache_key(name, context) @cache_backend.fetch_or_store(cache_key) do @delegate.resolve(name, context) end end |
#resolve_or_nil(name, context) ⇒ Class?
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.
Try to resolve a type, returning nil if not found.
98 99 100 101 102 |
# File 'lib/lutaml/model/cached_type_resolver.rb', line 98 def resolve_or_nil(name, context) resolve(name, context) rescue UnknownTypeError nil end |