class TwitterJekyll::FileCache
Cache class that writes to filesystem TODO: Do i really need to cache? @api private
Public Class Methods
new(path)
click to toggle source
# File lib/jekyll-twitter-plugin-2.rb, line 27 def initialize(path) @cache_folder = File.expand_path path FileUtils.mkdir_p @cache_folder end
Public Instance Methods
read(key)
click to toggle source
# File lib/jekyll-twitter-plugin-2.rb, line 32 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)
click to toggle source
# File lib/jekyll-twitter-plugin-2.rb, line 37 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
Private Instance Methods
cache_file(filename)
click to toggle source
# File lib/jekyll-twitter-plugin-2.rb, line 48 def cache_file(filename) File.join(@cache_folder, filename) end
cache_filename(cache_key)
click to toggle source
# File lib/jekyll-twitter-plugin-2.rb, line 52 def cache_filename(cache_key) "#{cache_key}.cache" end