class Octopress::Gist::Cache

Constants

GIST_CACHE_DIR

Public Class Methods

get_cache_path(dir, name, str) click to toggle source
# File lib/octopress-gist/cache.rb, line 21
def get_cache_path(dir, name, str)
  File.join(dir, "#{name}-#{Digest::MD5.hexdigest(str)}.html")
end
read_cache(options) click to toggle source
# File lib/octopress-gist/cache.rb, line 8
def read_cache(options)
  path = get_cache_path(GIST_CACHE_DIR, options[:gist_id], options.to_s)
  File.exist?(path) ? JSON.parse(File.read(path)) : nil
end
write_cache(contents, options) click to toggle source
# File lib/octopress-gist/cache.rb, line 13
def write_cache(contents, options)
  FileUtils.mkdir_p(GIST_CACHE_DIR) unless File.directory?(GIST_CACHE_DIR)
  path = get_cache_path(GIST_CACHE_DIR, options[:gist_id], options.to_s)
  File.open(path, 'w') do |f|
    f.print(contents.to_s)
  end
end