Class: DecisionAgent::Dmn::CachedDmnEvaluator
- Inherits:
-
Object
- Object
- DecisionAgent::Dmn::CachedDmnEvaluator
- Defined in:
- lib/decision_agent/dmn/cache.rb
Overview
Enhanced DMN Evaluator with Caching
Instance Attribute Summary collapse
-
#cache ⇒ Object
readonly
Returns the value of attribute cache.
-
#evaluator ⇒ Object
readonly
Returns the value of attribute evaluator.
Instance Method Summary collapse
-
#cache_stats ⇒ Object
Get cache statistics.
-
#clear_cache ⇒ Object
Clear cache.
-
#evaluate(context:) ⇒ Object
Evaluate with caching.
-
#initialize(dmn_model:, decision_id:, cache: nil, enable_caching: true) ⇒ CachedDmnEvaluator
constructor
A new instance of CachedDmnEvaluator.
-
#warm_cache(input_samples) ⇒ Object
Warm up cache with common inputs.
Constructor Details
#initialize(dmn_model:, decision_id:, cache: nil, enable_caching: true) ⇒ CachedDmnEvaluator
Returns a new instance of CachedDmnEvaluator.
160 161 162 163 164 165 166 167 168 169 170 171 |
# File 'lib/decision_agent/dmn/cache.rb', line 160 def initialize(dmn_model:, decision_id:, cache: nil, enable_caching: true) @dmn_model = dmn_model @decision_id = decision_id @cache = cache || EvaluationCache.new @enable_caching = enable_caching # Create the underlying evaluator @evaluator = Evaluators::DmnEvaluator.new( dmn_model: dmn_model, decision_id: decision_id ) end |
Instance Attribute Details
#cache ⇒ Object (readonly)
Returns the value of attribute cache.
158 159 160 |
# File 'lib/decision_agent/dmn/cache.rb', line 158 def cache @cache end |
#evaluator ⇒ Object (readonly)
Returns the value of attribute evaluator.
158 159 160 |
# File 'lib/decision_agent/dmn/cache.rb', line 158 def evaluator @evaluator end |
Instance Method Details
#cache_stats ⇒ Object
Get cache statistics
200 201 202 |
# File 'lib/decision_agent/dmn/cache.rb', line 200 def cache_stats @cache.statistics end |
#clear_cache ⇒ Object
Clear cache
205 206 207 |
# File 'lib/decision_agent/dmn/cache.rb', line 205 def clear_cache @cache.clear_results end |
#evaluate(context:) ⇒ Object
Evaluate with caching
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 |
# File 'lib/decision_agent/dmn/cache.rb', line 174 def evaluate(context:) return @evaluator.evaluate(context: context) unless @enable_caching # Generate context hash for cache key context_hash = generate_context_hash(context) # Try to get cached result cached_result = @cache.get_result(@decision_id, context_hash) return cached_result if cached_result # Evaluate and cache result result = @evaluator.evaluate(context: context) @cache.cache_result(@decision_id, context_hash, result) result end |