module CacheJSON::Base
Public Class Methods
included(base)
click to toggle source
# File lib/cache_json/base.rb, line 7 def self.included(base) base.extend(ClassMethods) end
Public Instance Methods
cache_expiring_soon?(args:, cache: nil)
click to toggle source
# File lib/cache_json/base.rb, line 20 def cache_expiring_soon?(args:, cache: nil) cache ||= Cache.new(args: args, options: self.class.cache_json_full_options) cache.cache_expiring_soon? end
check_cache(args:, cache: nil)
click to toggle source
# File lib/cache_json/base.rb, line 36 def check_cache(args:, cache: nil) cache ||= Cache.new(args: args, options: self.class.cache_json_full_options) cache.cached_results end
clear_cache!()
click to toggle source
# File lib/cache_json/base.rb, line 25 def clear_cache! Cache.new(options: self.class.cache_json_full_options).clear_cache! end
refresh_cache!(args:, cache: nil)
click to toggle source
# File lib/cache_json/base.rb, line 29 def refresh_cache!(args:, cache: nil) cache ||= Cache.new(args: args, options: self.class.cache_json_full_options) results = compute_results(**args) cache.cached_results = results results end
results(args = {})
click to toggle source
# File lib/cache_json/base.rb, line 11 def results(args = {}) raise ArgumentError, 'Must use keyword arguments' unless args.is_a?(Hash) options = self.class.cache_json_full_options cache = Cache.new(args: args, options: options) check_cache(args: args, cache: cache) || JSON.parse(refresh_cache!(args: args, cache: cache).to_json) # stringify keys end