Sha256: 932254f45221da100fcad7eaf80ce2698bf32406d5130fb2c2732e4676a234d9

Contents?: true

Size: 756 Bytes

Versions: 89

Compression:

Stored size: 756 Bytes

Contents

module MultiJson
  module OptionsCache
    extend self

    def reset
      @dump_cache = {}
      @load_cache = {}
    end

    def fetch(type, key)
      cache = instance_variable_get("@#{type}_cache")
      cache.key?(key) ? cache[key] : write(cache, key, &Proc.new)
    end

    private

    # Normally MultiJson is used with a few option sets for both dump/load
    # methods. When options are generated dynamically though, every call would
    # cause a cache miss and the cache would grow indefinitely. To prevent
    # this, we just reset the cache every time the number of keys outgrows
    # 1000.
    MAX_CACHE_SIZE = 1000

    def write(cache, key)
      cache.clear if cache.length >= MAX_CACHE_SIZE
      cache[key] = yield
    end
  end
end

Version data entries

89 entries across 78 versions & 14 rubygems

Version Path
logstash-output-scalyr-0.2.1.beta vendor/bundle/jruby/2.5.0/gems/multi_json-1.13.1/lib/multi_json/options_cache.rb
logstash-output-scalyr-0.2.0 vendor/bundle/jruby/2.5.0/gems/multi_json-1.13.1/lib/multi_json/options_cache.rb
logstash-output-scalyr-0.2.0.beta vendor/bundle/jruby/2.5.0/gems/multi_json-1.13.1/lib/multi_json/options_cache.rb
logstash-output-scalyr-0.1.26.beta vendor/bundle/jruby/2.5.0/gems/multi_json-1.13.1/lib/multi_json/options_cache.rb
logstash-output-scalyr-0.1.25.beta vendor/bundle/jruby/2.5.0/gems/multi_json-1.13.1/lib/multi_json/options_cache.rb
logstash-output-scalyr-0.1.24.beta vendor/bundle/jruby/2.5.0/gems/multi_json-1.13.1/lib/multi_json/options_cache.rb
logstash-output-scalyr-0.1.23.beta vendor/bundle/jruby/2.5.0/gems/multi_json-1.13.1/lib/multi_json/options_cache.rb
logstash-output-scalyr-0.1.22.beta vendor/bundle/jruby/2.5.0/gems/multi_json-1.13.1/lib/multi_json/options_cache.rb
logstash-output-scalyr-0.1.21.beta vendor/bundle/jruby/2.5.0/gems/multi_json-1.13.1/lib/multi_json/options_cache.rb
logstash-output-scalyr-0.1.20.beta vendor/bundle/jruby/2.5.0/gems/multi_json-1.13.1/lib/multi_json/options_cache.rb
logstash-output-scalyr-0.1.19.beta vendor/bundle/jruby/2.5.0/gems/multi_json-1.13.1/lib/multi_json/options_cache.rb
logstash-output-scalyr-0.1.18.beta vendor/bundle/jruby/2.5.0/gems/multi_json-1.13.1/lib/multi_json/options_cache.rb
logstash-output-scalyr-0.1.17.beta vendor/bundle/jruby/2.5.0/gems/multi_json-1.13.1/lib/multi_json/options_cache.rb
logstash-output-scalyr-0.1.16.beta vendor/bundle/jruby/2.5.0/gems/multi_json-1.13.1/lib/multi_json/options_cache.rb
logstash-output-scalyr-0.1.15.beta vendor/bundle/jruby/2.5.0/gems/multi_json-1.13.1/lib/multi_json/options_cache.rb
logstash-output-scalyr-0.1.14.beta vendor/bundle/jruby/2.5.0/gems/multi_json-1.13.1/lib/multi_json/options_cache.rb
logstash-output-scalyr-0.1.13 vendor/bundle/jruby/2.5.0/gems/multi_json-1.13.1/lib/multi_json/options_cache.rb
logstash-output-scalyr-0.1.12 vendor/bundle/jruby/2.5.0/gems/multi_json-1.13.1/lib/multi_json/options_cache.rb
logstash-output-scalyr-0.1.11.beta vendor/bundle/jruby/2.5.0/gems/multi_json-1.13.1/lib/multi_json/options_cache.rb
logstash-output-scalyr-0.1.10.beta vendor/bundle/jruby/2.5.0/gems/multi_json-1.13.1/lib/multi_json/options_cache.rb