Class: Relax2::FileCache

Inherits:
Object
  • Object
show all
Defined in:
lib/relax2/file_cache.rb

Instance Method Summary collapse

Constructor Details

#initialize(dirname, filename) ⇒ FileCache

Returns a new instance of FileCache.



5
6
7
8
# File 'lib/relax2/file_cache.rb', line 5

def initialize(dirname, filename)
  @cache_dir = cache_dir(dirname)
  @cache_path = File.join(@cache_dir, filename)
end

Instance Method Details

#clearObject



27
28
29
# File 'lib/relax2/file_cache.rb', line 27

def clear
  File.delete(@cache_path) if File.exist?(@cache_path)
end

#loadObject



18
19
20
# File 'lib/relax2/file_cache.rb', line 18

def load
  File.read(@cache_path) if Dir.exist?(@cache_dir) && File.exist?(@cache_path)
end

#save(data) ⇒ Object



22
23
24
25
# File 'lib/relax2/file_cache.rb', line 22

def save(data)
  Dir.mkdir(@cache_dir) unless Dir.exist?(@cache_dir)
  File.write(@cache_path, data)
end