Class: TwitterJekyll::FileCache Private
- Inherits:
-
Object
- Object
- TwitterJekyll::FileCache
- Defined in:
- lib/jekyll-twitter-plugin.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Cache class that writes to filesystem TODO: Do i really need to cache?
Instance Method Summary collapse
-
#initialize(path) ⇒ FileCache
constructor
private
A new instance of FileCache.
- #read(key) ⇒ Object private
- #write(key, data) ⇒ Object private
Constructor Details
#initialize(path) ⇒ FileCache
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of FileCache.
25 26 27 28 |
# File 'lib/jekyll-twitter-plugin.rb', line 25 def initialize(path) @cache_folder = File. path FileUtils.mkdir_p @cache_folder end |
Instance Method Details
#read(key) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
30 31 32 33 |
# File 'lib/jekyll-twitter-plugin.rb', line 30 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
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
35 36 37 38 39 40 41 42 |
# File 'lib/jekyll-twitter-plugin.rb', line 35 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 |