class AppCache::LocalFileCache
Public Class Methods
new(path = '')
click to toggle source
# File lib/app_cache/local_file_cache.rb, line 3 def initialize(path = '') if ! path.empty? @file_path = path else @file_path = '/tmp' end end
Public Instance Methods
del(key)
click to toggle source
# File lib/app_cache/local_file_cache.rb, line 27 def del key File.delete("#{@file_path}/#{key}") if has? key end
flush()
click to toggle source
# File lib/app_cache/local_file_cache.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/app_cache/local_file_cache.rb, line 19 def get key has?(key) ? File.read("#{@file_path}/#{key}") : nil end
has?(key)
click to toggle source
# File lib/app_cache/local_file_cache.rb, line 23 def has? key File.exists?("#{@file_path}/#{key}") end
set(key, value)
click to toggle source
# File lib/app_cache/local_file_cache.rb, line 11 def set(key, value) FileUtils.mkdir_p("#{@file_path}") #File.write("#{@file_path}/#{key}", value) file = File.open("#{@file_path}/#{key}", "w") file.write(value) file.close end