class Tr8n::CacheAdapters::File
Public Class Methods
cache_path()
click to toggle source
# File lib/tr8n/cache_adapters/file.rb, line 35 def self.cache_path "#{Tr8n.config.cache[:path]}/#{Tr8n.config.cache[:version]}" end
file_path(key)
click to toggle source
# File lib/tr8n/cache_adapters/file.rb, line 39 def self.file_path(key) File.join(cache_path, "#{key}.json") end
Public Instance Methods
cache_name()
click to toggle source
# File lib/tr8n/cache_adapters/file.rb, line 43 def cache_name 'file' end
clear(opts = {})
click to toggle source
# File lib/tr8n/cache_adapters/file.rb, line 81 def clear(opts = {}) warn('This is a readonly cache') end
delete(key, opts = {})
click to toggle source
# File lib/tr8n/cache_adapters/file.rb, line 73 def delete(key, opts = {}) warn('This is a readonly cache') end
exist?(key, opts = {})
click to toggle source
# File lib/tr8n/cache_adapters/file.rb, line 77 def exist?(key, opts = {}) File.exists?(self.class.file_path(key)) end
fetch(key, opts = {}) { || ... }
click to toggle source
# File lib/tr8n/cache_adapters/file.rb, line 52 def fetch(key, opts = {}) info("Fetching key: #{key}") path = self.class.file_path(key) if File.exists?(path) info("Cache hit: #{key}") return JSON.parse(File.read(path)) end info("Cache miss: #{key}") return nil unless block_given? yield end
read_only?()
click to toggle source
# File lib/tr8n/cache_adapters/file.rb, line 85 def read_only? true end
segmented?()
click to toggle source
# File lib/tr8n/cache_adapters/file.rb, line 47 def segmented? return true if Tr8n.config.cache[:segmented].nil? Tr8n.config.cache[:segmented] end
store(key, data, opts = {})
click to toggle source
# File lib/tr8n/cache_adapters/file.rb, line 69 def store(key, data, opts = {}) warn('This is a readonly cache') end