Class: TwitterJekyll::FileCache Private

Inherits:
Object
  • Object
show all
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

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.



28
29
30
31
# File 'lib/jekyll-twitter-plugin.rb', line 28

def initialize(path)
  @cache_folder = File.expand_path 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.



33
34
35
36
# File 'lib/jekyll-twitter-plugin.rb', line 33

def read(key)
  file_to_read = cache_file(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.



38
39
40
41
42
43
44
# File 'lib/jekyll-twitter-plugin.rb', line 38

def write(key, data)
  file_to_write = cache_file(key)

  File.open(file_to_write, "w") do |f|
    f.write(JSON.generate(data.to_h))
  end
end