Sha256: d1f138498376bbea5165af8606c8eb8f0b9ce0e3dd3247c44033ded10717f695
Contents?: true
Size: 653 Bytes
Versions: 3
Compression:
Stored size: 653 Bytes
Contents
module Bunch module Cache end class << Cache def init @cache = Hash.new { |h, k| h[k] = {} } end def stored?(fn) @cache.keys.include?(fn) end def read(fn) @cache[fn][:content] end def mtime(fn) @cache[fn][:mtime] end def write(fn, mtime, content) @cache[fn] = {:mtime => mtime, :content => content} end def fetch(fn, &blk) current_mtime = File.mtime(fn) if stored?(fn) && mtime(fn) == current_mtime read(fn) else content = blk.call write(fn, current_mtime, content) content end end end Cache.init end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
bunch-0.2.2 | lib/bunch/cache.rb |
bunch-0.2.1 | lib/bunch/cache.rb |
bunch-0.2.0 | lib/bunch/cache.rb |