Module: EacRubyUtils::SimpleCache

Constant Summary collapse

UNCACHED_METHOD_NAME_SUFFIX =
'_uncached'
UNCACHED_METHOD_PATTERN =
/\A(\s+)_#{::Regexp.quote(UNCACHED_METHOD_NAME_SUFFIX)}\z/.freeze

Class Method Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/eac_ruby_utils/simple_cache.rb', line 14

def method_missing(method, *args, &block)
  if respond_to?(::EacRubyUtils::SimpleCache.uncached_method_name(method), true)
    call_method_with_cache(method, args, &block)
  else
    super
  end
end

Class Method Details

.uncached_method_name(method_name) ⇒ Object



9
10
11
# File 'lib/eac_ruby_utils/simple_cache.rb', line 9

def uncached_method_name(method_name)
  "#{method_name}#{UNCACHED_METHOD_NAME_SUFFIX}"
end

Instance Method Details

#reset_cache(*keys) ⇒ Object



30
31
32
33
34
35
36
# File 'lib/eac_ruby_utils/simple_cache.rb', line 30

def reset_cache(*keys)
  if keys.any?
    keys.each { |key| cache_keys.delete(key) }
  else
    @cache_keys = nil
  end
end

#respond_to_missing?(method, include_all = false) ⇒ Boolean

Returns:



22
23
24
25
26
27
28
# File 'lib/eac_ruby_utils/simple_cache.rb', line 22

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