Sha256: 1b3099581d5b881548d8c7f2996b7657a56694a73bbba5ecef6594cec5c1f5b4

Contents?: true

Size: 437 Bytes

Versions: 70

Compression:

Stored size: 437 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

70 entries across 69 versions & 6 rubygems

Version Path
arcabouco-0.2.13 vendor/bundle/gems/compass-1.0.3/lib/compass/quick_cache.rb
compass-1.0.3 lib/compass/quick_cache.rb
compass-1.1.0.alpha.3 lib/compass/quick_cache.rb
compass-1.1.0.alpha.2 lib/compass/quick_cache.rb
compass-1.1.0.alpha.1 lib/compass/quick_cache.rb
compass-1.1.0.alpha.0 lib/compass/quick_cache.rb
compass-1.0.1 lib/compass/quick_cache.rb
compass-1.0.0 lib/compass/quick_cache.rb
compass-1.0.0.rc.1 lib/compass/quick_cache.rb
compass-1.0.0.rc.0 lib/compass/quick_cache.rb
compass-0.12.7 lib/compass/quick_cache.rb
compass-1.0.0.alpha.21 lib/compass/quick_cache.rb
compass-1.0.0.alpha.20 lib/compass/quick_cache.rb
sadui-0.0.4 vendor/bundle/ruby/2.0.0/gems/compass-0.12.3/lib/compass/quick_cache.rb
sadui-0.0.4 vendor/bundle/ruby/2.1.0/gems/compass-0.12.3/lib/compass/quick_cache.rb
compass-0.12.6 lib/compass/quick_cache.rb
compass-0.12.5 lib/compass/quick_cache.rb
compass-0.12.4 lib/compass/quick_cache.rb
compass-1.0.0.alpha.19 lib/compass/quick_cache.rb
compass-0.12.3 lib/compass/quick_cache.rb