Sha256: 949ca9de5351946d2390c0d370c1a8b4d3e1878978b6b3ecc1e7ab71a2938f92

Contents?: true

Size: 548 Bytes

Versions: 22

Compression:

Stored size: 548 Bytes

Contents

require 'thread'

module JMESPath
  class CachingParser

    def initialize(options = {})
      @parser = options[:parser] || Parser.new(options)
      @mutex = Mutex.new
      @cache = {}
    end

    def parse(expression)
      if cached = @cache[expression]
        cached
      else
        cache_expression(expression)
      end
    end

    private

    def cache_expression(expression)
      @mutex.synchronize do
        @cache.clear if @cache.size > 1000
        @cache[expression] = @parser.parse(expression)
      end
    end

  end
end

Version data entries

22 entries across 22 versions & 3 rubygems

Version Path
jmespath-1.6.1 lib/jmespath/caching_parser.rb
jmespath-1.6.0 lib/jmespath/caching_parser.rb
jmespath-1.5.0 lib/jmespath/caching_parser.rb
jmespath-1.4.0 lib/jmespath/caching_parser.rb
ivanvc-logstash-input-s3-3.1.1.4 vendor/local/gems/jmespath-1.3.1/lib/jmespath/caching_parser.rb
ivanvc-logstash-input-s3-3.1.1.3 vendor/local/gems/jmespath-1.3.1/lib/jmespath/caching_parser.rb
ivanvc-logstash-input-s3-3.1.1.2 vendor/local/gems/jmespath-1.3.1/lib/jmespath/caching_parser.rb
jmespath-1.3.1 lib/jmespath/caching_parser.rb
jmespath-1.3.0 lib/jmespath/caching_parser.rb
jmespath-1.2.4 lib/jmespath/caching_parser.rb
jmespath-1.2.3 lib/jmespath/caching_parser.rb
jmespath-1.2.2 lib/jmespath/caching_parser.rb
jmespath-1.2.1 lib/jmespath/caching_parser.rb
jmespath-1.2 lib/jmespath/caching_parser.rb
jmespath-1.1.3 lib/jmespath/caching_parser.rb
jmespath-1.1.2 lib/jmespath/caching_parser.rb
jmespath-1.1.1 lib/jmespath/caching_parser.rb
jmespath-1.1.0 lib/jmespath/caching_parser.rb
aws-codedeploy-agent-0.0.3 vendor/gems/jmespath-1.0.1/lib/jmespath/caching_parser.rb
jmespath-1.0.2 lib/jmespath/caching_parser.rb