module Keystok::Cache
Module for handling cache write and read operations
Public Instance Methods
cache_file_exist?()
click to toggle source
# File lib/keystok/cache.rb, line 14 def cache_file_exist? File.exist?(cache_file_path) end
cache_file_path(tmp_dir = nil)
click to toggle source
# File lib/keystok/cache.rb, line 9 def cache_file_path(tmp_dir = nil) tmp_dir ||= (@config && @config[:tmp_dir]) ? @config[:tmp_dir] : '.' @cache_file_path ||= File.join(tmp_dir, 'keystok_cache.data') end
cache_stream(method = :read)
click to toggle source
# File lib/keystok/cache.rb, line 18 def cache_stream(method = :read) case method when :write mode = 'wb' else mode = 'r' end File.open(cache_file_path, mode) end
load_cache(iostream = nil)
click to toggle source
# File lib/keystok/cache.rb, line 28 def load_cache(iostream = nil) Keystok.logger.warn('Loading data from cache') iostream ||= cache_stream iostream.read end
write_cache(cache_data, iostream = nil)
click to toggle source
# File lib/keystok/cache.rb, line 34 def write_cache(cache_data, iostream = nil) iostream ||= cache_stream(:write) iostream.write(cache_data) iostream.flush end