Sha256: 1cc24762df82b884cf9d41dd2e747ab563e7fa5c2f5ca50e2637a431bed99fe5
Contents?: true
Size: 1.06 KB
Versions: 75
Compression:
Stored size: 1.06 KB
Contents
# frozen_string_literal: true module EacRubyUtils module SimpleCache UNCACHED_METHOD_PATTERN = /\A(\s+)_uncached\z/.freeze def method_missing(method, *args, &block) uncached_method = "#{method}_uncached" if respond_to?(uncached_method, true) call_method_with_cache(uncached_method, args, &block) else super end end def respond_to_missing?(method, include_all = false) if method.to_s.end_with?('_uncached') super else respond_to?("#{method}_uncached", true) || super end end def reset_cache(*keys) if keys.any? keys.each { |key| cache_keys.delete(key) } else @cache_keys = nil end end private def call_method_with_cache(method, args, &block) raise 'Não é possível realizar o cache de métodos com bloco' if block key = ([method] + args).join('@@@') cache_keys[key] = send(method, *args) unless cache_keys.key?(key) cache_keys[key] end def cache_keys @cache_keys ||= {} end end end
Version data entries
75 entries across 75 versions & 3 rubygems