Class: SvgConform::ClassificationCache
- Inherits:
-
Object
- Object
- SvgConform::ClassificationCache
- Defined in:
- lib/svg_conform/classification_cache.rb
Overview
Cache for requirement classification results Instance-level (per SaxValidationHandler) to avoid shared mutable state No mutexes needed - each handler has its own cache
Instance Method Summary collapse
-
#clear(key = nil) ⇒ Object
Clear specific key or entire cache.
-
#fetch(key) ⇒ Object
Fetch from cache or compute the value.
-
#initialize ⇒ ClassificationCache
constructor
A new instance of ClassificationCache.
-
#key?(key) ⇒ Boolean
Check if key exists in cache.
-
#size ⇒ Object
Return number of cached entries.
Constructor Details
#initialize ⇒ ClassificationCache
Returns a new instance of ClassificationCache.
8 9 10 |
# File 'lib/svg_conform/classification_cache.rb', line 8 def initialize @cache = {} end |
Instance Method Details
#clear(key = nil) ⇒ Object
Clear specific key or entire cache
18 19 20 21 22 23 24 |
# File 'lib/svg_conform/classification_cache.rb', line 18 def clear(key = nil) if key @cache.delete(key) else @cache.clear end end |
#fetch(key) ⇒ Object
Fetch from cache or compute the value
13 14 15 |
# File 'lib/svg_conform/classification_cache.rb', line 13 def fetch(key) @cache[key] ||= yield end |
#key?(key) ⇒ Boolean
Check if key exists in cache
32 33 34 |
# File 'lib/svg_conform/classification_cache.rb', line 32 def key?(key) @cache.key?(key) end |
#size ⇒ Object
Return number of cached entries
27 28 29 |
# File 'lib/svg_conform/classification_cache.rb', line 27 def size @cache.size end |