Class Atom::FileCache
In: lib/atom/cache.rb
Parent: Object

uses a local directory to store cache files

Methods

[]   []=   delete   new   safe   to_file  

Public Class methods

[Source]

# File lib/atom/cache.rb, line 145
    def initialize dir
      @dir = dir
    end

Public Instance methods

[Source]

# File lib/atom/cache.rb, line 162
    def [] key
      File.read(self.to_file(key))
    rescue Errno::ENOENT
      nil
    end

[Source]

# File lib/atom/cache.rb, line 168
    def []= key, value
      File.open(self.to_file(key), 'w') do |f|
        f.write(value)
      end
    end

[Source]

# File lib/atom/cache.rb, line 174
    def delete key
      File.delete(self.to_file(key))
    end

turns a URL into a safe filename

[Source]

# File lib/atom/cache.rb, line 154
    def safe filename
      filemd5 = MD5.hexdigest(filename)
      filename = filename.sub(/^\w+:\/\//, '')
      filename = filename.gsub(/[?\/:|]+/, ',')

      filename + "," + filemd5
    end

[Source]

# File lib/atom/cache.rb, line 149
    def to_file(key)
      @dir + "/" + self.safe(key)
    end

[Validate]