Class: NerRuby::ModelCache

Inherits:
Object
  • Object
show all
Defined in:
lib/ner_ruby/model_cache.rb

Instance Method Summary collapse

Constructor Details

#initializeModelCache

Returns a new instance of ModelCache.



5
6
7
8
# File 'lib/ner_ruby/model_cache.rb', line 5

def initialize
  @cache = {}
  @mutex = Mutex.new
end

Instance Method Details

#clearObject



22
23
24
# File 'lib/ner_ruby/model_cache.rb', line 22

def clear
  @mutex.synchronize { @cache.clear }
end

#get(key) ⇒ Object



10
11
12
# File 'lib/ner_ruby/model_cache.rb', line 10

def get(key)
  @mutex.synchronize { @cache[key] }
end

#has?(key) ⇒ Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/ner_ruby/model_cache.rb', line 18

def has?(key)
  @mutex.synchronize { @cache.key?(key) }
end

#set(key, value) ⇒ Object



14
15
16
# File 'lib/ner_ruby/model_cache.rb', line 14

def set(key, value)
  @mutex.synchronize { @cache[key] = value }
end

#sizeObject



26
27
28
# File 'lib/ner_ruby/model_cache.rb', line 26

def size
  @mutex.synchronize { @cache.size }
end