Sha256: 20ad97d732e76c89d53f10624f33dda8e904dee033a4f0873ca78bdb5fab01f6

Contents?: true

Size: 665 Bytes

Versions: 2

Compression:

Stored size: 665 Bytes

Contents

# encoding: UTF-8

module Bunch
  def self.SimpleCache(*args)
    SimpleCache.new(*args)
  end

  class SimpleCache
    Result = Struct.new(:result)

    def initialize(processor_class, *args)
      @processor_class, @args = processor_class, args
      @cache = nil
      @hache = nil
    end

    def new(tree)
      check_cache!(tree)
      @cache ||= begin
        processor = @processor_class.new(tree, *@args)
        processor.result
      end
      Result.new(@cache.dup)
    end

    private

    def check_cache!(tree)
      hash = ContentHash.new(tree).result
      if hash != @hache
        @cache = nil
        @hache = hash
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
bunch-1.0.0pre2 lib/bunch/simple_cache.rb
bunch-1.0.0pre1 lib/bunch/simple_cache.rb