class LocalFileCache

Constants

VERSION

Public Class Methods

new(path = '') click to toggle source
# File lib/localFileCache.rb, line 4
def initialize(path = '')
  if ! path.empty?
    @file_path = path
  elsif ! ENV['FILECACHE_PATH'].nil? && ! ENV['FILECACHE_PATH'].empty?
    @file_path = ENV['FILECACHE_PATH']
  else
    @file_path = '/tmp'
  end
end

Public Instance Methods

delete(key) click to toggle source
# File lib/localFileCache.rb, line 27
def delete key
  File.delete("#{@file_path}/#{key}") if has? key
end
flush() click to toggle source
# File lib/localFileCache.rb, line 31
def flush
  Dir.foreach(@file_path) do |item|
    next if item == '.' || item == '..'
    delete item
  end
  Dir.rmdir(@file_path)
end
get(key) click to toggle source
# File lib/localFileCache.rb, line 19
def get key
  has?(key) ? File.read("#{@file_path}/#{key}") : nil
end
has?(key) click to toggle source
# File lib/localFileCache.rb, line 23
def has? key
  File.exists?("#{@file_path}/#{key}")
end
set(key, value) click to toggle source
# File lib/localFileCache.rb, line 14
def set(key, value)
  FileUtils.mkdir_p("#{@file_path}")
  File.write("#{@file_path}/#{key}", value)
end