class WithTimedCache::JSONCache

Public Class Methods

new(key, opts = {}) click to toggle source
Calls superclass method WithTimedCache::Cache::new
# File lib/with_timed_cache/json_cache.rb, line 6
def initialize(key, opts = {})
  super
  @location = opts[:location] || File.join("tmp", filename)
  @location = File.join(@location, filename) if File.directory?(@location)
end

Public Instance Methods

read() click to toggle source
# File lib/with_timed_cache/json_cache.rb, line 12
def read
  JSON.parse(File.read(@location), symbolize_names: true)
end
write(data) click to toggle source
# File lib/with_timed_cache/json_cache.rb, line 16
def write(data)
  File.open(@location, 'w') { |f| f.write data.to_json }
end