Class: Exchange::Cache::File
Overview
A class that allows to store api call results in files. THIS NOT A RECOMMENDED CACHING OPTION! It just may be necessary to cache large files somewhere, this class allows you to do that
Instance Method Summary (collapse)
-
- (Object) cached(api, opts = {}) { ... }
returns either cached data from a stored file or stores a file.
Instance Method Details
- (Object) cached(api, opts = {}) { ... }
returns either cached data from a stored file or stores a file. This method has to be the same in all the cache classes in order for the configuration binding to work
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/exchange/cache/file.rb', line 23 def cached api, opts={}, &block today = Time.now dir = config.path path = ::File.join(dir, key(api, opts[:cache_period])) if ::File.exists?(path) result = opts[:plain] ? ::File.read(path) : ::File.read(path).decachify else result = super if result && !result.to_s.empty? make_sure_exists dir clean! dir, api ::File.open(path, 'w') {|f| f.write(result.cachify) } end end result end |