Sha256: 81af60fa811a6fea941b93b463138f3d0e142201c8c4cbcb02e971941c290f3e

Contents?: true

Size: 452 Bytes

Versions: 2

Compression:

Stored size: 452 Bytes

Contents

module QuickCache

  # cache a value in memory for just a few seconds
  # This can speed up reads of values that change relatively infrequently
  # but might be read many times in a short burst of reads.
  def quick_cache(key, ttl = 1)
    @quick_cache ||= {}
    if @quick_cache[key] && @quick_cache[key].first > Time.now - ttl
      @quick_cache[key].last
    else
      (@quick_cache[key] = [Time.now, yield]).last
    end
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
compass-sourcemaps-0.12.3.sourcemaps.a4836f1 lib/compass/quick_cache.rb
compass-sourcemaps-0.12.2.sourcemaps.57a186c lib/compass/quick_cache.rb