Sha256: f8c68d735c02e04f6e1adba21f69f1df00eaaad51e49f92284c6cf686c529374

Contents?: true

Size: 588 Bytes

Versions: 6

Compression:

Stored size: 588 Bytes

Contents

require 'date'

module PairingMatrix
  def self.enable_caching=(enabled)
    @cache_enabled = enabled
  end

  def self.cache_enabled
    @cache_enabled
  end

  class CommitCache
    def initialize
      @cache = {}
      @timestamp = Date.today
    end

    def put(date, response)
      @cache[date] = response
    end

    def get(date)
      return nil unless PairingMatrix.cache_enabled

      if Date.today == @timestamp
        @cache[date]
      else
        invalidate_cache
        nil
      end
    end

    private
    def invalidate_cache
      @cache = {}
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
pairing_matrix-3.0.0 lib/pairing_matrix/cache/commit_cache.rb
pairing_matrix-2.3.1 lib/pairing_matrix/commit_cache.rb
pairing_matrix-2.3 lib/pairing_matrix/commit_cache.rb
pairing_matrix-2.2 lib/pairing_matrix/commit_cache.rb
pairing_matrix-2.1.1 lib/pairing_matrix/commit_cache.rb
pairing_matrix-2.1 lib/pairing_matrix/commit_cache.rb