class Stormy::Caches::FileCache
Public Class Methods
new(app)
click to toggle source
Calls superclass method
Stormy::Caches::Base::new
# File lib/stormy/caches/file_cache.rb, line 5 def initialize(app) super @base_path = app.join("tmp","cache") clean_path end
Protected Instance Methods
build_cache_key(category,key)
click to toggle source
# File lib/stormy/caches/file_cache.rb, line 13 def build_cache_key(category,key) path("#{category}--#{key.gsub("/","--")}.cache") end
clean_path()
click to toggle source
# File lib/stormy/caches/file_cache.rb, line 34 def clean_path path_exists = File.directory?(@base_path) if path_exists FileUtils.rm Dir.glob(path("*.cache")) else FileUtils.mkpath(@base_path) end end
get(category,key)
click to toggle source
# File lib/stormy/caches/file_cache.rb, line 18 def get(category,key) filename = build_cache_key(category,key) if File.exists?(filename) File.read(filename) end end
path(file)
click to toggle source
# File lib/stormy/caches/file_cache.rb, line 43 def path(file) File.join(@base_path,file) end
put(category,key,value)
click to toggle source
# File lib/stormy/caches/file_cache.rb, line 26 def put(category,key,value) filename = build_cache_key(category,key) File.open(filename,"wt") do |fp| fp.write(value) end value end