Module: Jat::Plugins::SimpleApiMapsCache::MapsCacheClassMethods

Defined in:
lib/jat/plugins/simple_api/plugins/simple_api_maps_cache/simple_api_maps_cache.rb

Instance Method Summary collapse

Instance Method Details

#maps_cacheObject

Caches up to ‘:cached_maps_count` maps for each serializer. Removes earliest value if new value exceeds limit.



27
28
29
30
31
32
# File 'lib/jat/plugins/simple_api/plugins/simple_api_maps_cache/simple_api_maps_cache.rb', line 27

def maps_cache
  @maps_cache ||= Hash.new do |cache, cache_key|
    cache.shift if cache.length >= jat_class.config[:cached_maps_count] # protect from memory leak
    cache[cache_key] = EnumDeepFreeze.call(yield)
  end
end