Sha256: d48211621dda64f8caab125bbf33cfa976f40cb4d73b89eda587134de4f2034d
Contents?: true
Size: 1.23 KB
Versions: 6
Compression:
Stored size: 1.23 KB
Contents
class Kiss class CachedFile _attr_accessor :path, :content, :last_modified_at, :cached_at def new_with_path(path) @_path = path reload end def reload now = Time.now changed = false if File.file?(path) mtime = File.symlink?(path) ? File.lstat(path).mtime : File.mtime(path) content = nil if last_modified_at && last_modified_at < mtime if !content content ||= ? File.read(path) last_modified_at = mtime changed = true end elsif content content = nil last_modified_at = nil changed = true end cached_at = now return changed end end class CachedRubyFile < CachedFile end class FileCache _attr_accessor :cached_files_by_path, :should_reload_files def initialize(should_reload_files = true) @_cached_files_by_path = {} @_should_reload_files = should_reload_files end def file_for_path(path) file = @_cached_files_by_path[path] if !file file = @_cached_files_by_path[path] = CachedFile.new_with_path(path) else file.reload if should_reload_files end return file end end end
Version data entries
6 entries across 6 versions & 1 rubygems