class TinyStruct::MemoryCache

Maintains an in-memory cache of the defined `TinyStruct` classes, such that classes with the same attribute list do not end up getting created twice.

This cache makes performance quite a bit better since looping through `ObjectSpace` takes a while, but takes a hit on memory because everything is now stored. Also prevents the classes from being freed if they were created anonymously and could have otherwise have been freed.

Attributes

cache[R]

Public Class Methods

new() click to toggle source
# File lib/tiny_struct/memory_cache.rb, line 12
def initialize
  @cache = {}
end

Public Instance Methods

[](members) click to toggle source
# File lib/tiny_struct/memory_cache.rb, line 20
def [](members)
  cache[members]
end
[]=(members, clazz) click to toggle source
# File lib/tiny_struct/memory_cache.rb, line 16
def []=(members, clazz)
  cache[members] = clazz
end