Sha256: 1e4fdc89d4e9c5a9d51666b6ede89441ba9e79c7344e65f783526adbee749dec

Contents?: true

Size: 509 Bytes

Versions: 3

Compression:

Stored size: 509 Bytes

Contents

require 'thread'

module JMESPath
  class CachingParser

    def initialize(parser)
      @parser = parser
      @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

3 entries across 3 versions & 1 rubygems

Version Path
burtpath-1.1.2 lib/jmespath/caching_parser.rb
burtpath-1.1.1 lib/jmespath/caching_parser.rb
burtpath-1.1.0 lib/jmespath/caching_parser.rb