Class: SvgConform::ClassificationCache

Inherits:
Object
  • Object
show all
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

Constructor Details

#initializeClassificationCache

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

Returns:

  • (Boolean)


32
33
34
# File 'lib/svg_conform/classification_cache.rb', line 32

def key?(key)
  @cache.key?(key)
end

#sizeObject

Return number of cached entries



27
28
29
# File 'lib/svg_conform/classification_cache.rb', line 27

def size
  @cache.size
end