class AwsDevUtils::CacheWrapper

Public Class Methods

new(client, exp=60, client_name: nil) click to toggle source

Initialize a new CacheWrapper, internal use only. @param client [Aws client, NextTokenWrapper, RetryWrapper] @param exp [Integer] - the key-value timeout

# File lib/aws-dev-utils/cache_wrapper.rb, line 10
def initialize client, exp=60, client_name: nil
    @client = client
    @exp = exp
    @client_name = client_name || client.class.name
  end

Public Instance Methods

method_missing(m, *args, &block) click to toggle source
# File lib/aws-dev-utils/cache_wrapper.rb, line 16
def method_missing m, *args, &block
  do_call(m, args.first || {})
end

Private Instance Methods

cache_key(m, params) click to toggle source
# File lib/aws-dev-utils/cache_wrapper.rb, line 22
def cache_key m, params
  [@client_name, m, params.deep_sort, @exp]
end
do_call(m, params) click to toggle source
# File lib/aws-dev-utils/cache_wrapper.rb, line 26
def do_call m, params
  Cache.instance.fetch(cache_key(m, params), @exp) {
    nested_hash(@client.send(m, params))
  }
end