Sha256: d19c7c5b955b91a3e340d40b5c49fb0218176665950653a7be98127e1beda40c
Contents?: true
Size: 665 Bytes
Versions: 6
Compression:
Stored size: 665 Bytes
Contents
module Bunch module Cache end class << Cache def initialize @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.initialize end
Version data entries
6 entries across 6 versions & 1 rubygems