Class: TwitterJekyll::FileCache
- Inherits:
-
Object
- Object
- TwitterJekyll::FileCache
- Defined in:
- lib/jekyll-twitter-plugin.rb
Instance Method Summary collapse
-
#initialize(path) ⇒ FileCache
constructor
A new instance of FileCache.
- #read(key) ⇒ Object
- #write(key, data) ⇒ Object
Constructor Details
#initialize(path) ⇒ FileCache
Returns a new instance of FileCache.
22 23 24 25 |
# File 'lib/jekyll-twitter-plugin.rb', line 22 def initialize(path) @cache_folder = File. path FileUtils.mkdir_p @cache_folder end |
Instance Method Details
#read(key) ⇒ Object
27 28 29 30 |
# File 'lib/jekyll-twitter-plugin.rb', line 27 def read(key) file_to_read = cache_file(cache_filename(key)) JSON.parse(File.read(file_to_read)) if File.exist?(file_to_read) end |
#write(key, data) ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'lib/jekyll-twitter-plugin.rb', line 32 def write(key, data) file_to_write = cache_file(cache_filename(key)) data_to_write = JSON.generate data.to_h File.open(file_to_write, "w") do |f| f.write(data_to_write) end end |