Module: PACacheProxy::ClassMethods

Defined in:
lib/pa_proxies/pa_cache_proxy.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(base) ⇒ Object



7
8
9
10
11
12
# File 'lib/pa_proxies/pa_cache_proxy.rb', line 7

def self.extended(base)
  class << base
    alias_method :new_without_cache, :new unless method_defined?(:new_without_cache)
    alias_method :new, :new_with_cache
  end
end

Instance Method Details

#new_with_cache(*args) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/pa_proxies/pa_cache_proxy.rb', line 14

def new_with_cache(*args)
  t_cache_id = self.cache_id(*args)
  unless (t_cache_id.nil?) or (self.proxy_cache[t_cache_id].nil?)
    self.proxy_cache[t_cache_id].set_uncacheable_args(*args)
    object = self.proxy_cache[t_cache_id]
  else
    object = self.new_without_cache(*args)
    self.proxy_cache[t_cache_id] = object unless t_cache_id.nil?
  end
  object
end