class SgtnClient::Core::Cache

Constants

Entry

Public Class Methods

clear() click to toggle source
# File lib/sgtn-client/core/cache.rb, line 28
def self.clear
    SgtnClient.logger.debug "[Cache][clear]clear cache!"
    @@data = Hash.new
end
get(key) click to toggle source
# File lib/sgtn-client/core/cache.rb, line 16
def self.get(key)
    SgtnClient.logger.debug "[Cache][get]get cache for key: " + key
    return @@data&.dig(key)
end
initialize(disabled=false, opts={}) click to toggle source
# File lib/sgtn-client/core/cache.rb, line 10
def self.initialize(disabled=false, opts={})
    @@opts = opts
    SgtnClient.logger.debug "[Cache][initialize] Disable cache? #{disabled}"
    @@data = Hash.new
end
put(key, items, ttl=nil) click to toggle source
# File lib/sgtn-client/core/cache.rb, line 21
def self.put(key, items, ttl=nil)
    ttl ||= @@opts[:ttl]
    # hours from new
    SgtnClient.logger.debug "[Cache][put]put cache for key '" + key + "' with expired time at'" + (Time.now + ttl*60).to_s
    @@data[key] = Entry.new(Time.now + ttl*60, items)
end