Module: QuickCache

Included in:
Compass
Defined in:
lib/compass/quick_cache.rb

Instance Method Summary collapse

Instance Method Details

#quick_cache(key, ttl = 1) ⇒ Object

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.



6
7
8
9
10
11
12
13
# File 'lib/compass/quick_cache.rb', line 6

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