Class: Relax2::FileCache
- Inherits:
-
Object
- Object
- Relax2::FileCache
- Defined in:
- lib/relax2/file_cache.rb
Instance Method Summary collapse
- #clear ⇒ Object
-
#initialize(dirname, filename) ⇒ FileCache
constructor
A new instance of FileCache.
- #load ⇒ Object
- #save(data) ⇒ Object
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
#clear ⇒ Object
27 28 29 |
# File 'lib/relax2/file_cache.rb', line 27 def clear File.delete(@cache_path) if File.exist?(@cache_path) end |
#load ⇒ Object
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 |