Module: ObjectCache

Included in:
MatrixCache, VectorCache
Defined in:
lib/gosling/object_cache.rb

Instance Method Summary collapse

Instance Method Details

#clearObject



14
15
16
# File 'lib/gosling/object_cache.rb', line 14

def clear
  @cache.clear
end

#getObject



25
26
27
28
29
30
31
32
33
# File 'lib/gosling/object_cache.rb', line 25

def get
  if @cache.empty?
    self.create
  else
    obj = @cache.delete(@cache.keys.first)
    obj.unfreeze
    obj
  end
end

#recycle(obj) ⇒ Object



18
19
20
21
22
23
# File 'lib/gosling/object_cache.rb', line 18

def recycle(obj)
  return if @cache.key?(obj.object_id)
  self.reset(obj)
  obj.freeze
  @cache[obj.object_id] = obj
end

#sizeObject



35
36
37
# File 'lib/gosling/object_cache.rb', line 35

def size
  @cache.size
end