Module: Cachengue::Namespace

Defined in:
lib/cachengue/namespace.rb

Instance Method Summary collapse

Instance Method Details

#cachengue(options = {}) ⇒ Object



5
6
7
8
9
10
11
12
# File 'lib/cachengue/namespace.rb', line 5

def cachengue(options = {})
  if block_given?
    # Proc.new is the block passed as argument.
    Caching.fetch(self, nil, [], options, &Proc.new)
  else
    Proxy.new(self, options)
  end
end

#cachengue_clearObject



40
41
42
43
44
45
46
# File 'lib/cachengue/namespace.rb', line 40

def cachengue_clear
  __cachengue_namespaces__.inject({}) do |results, (namespace, strategy)|
    results.merge!(
      namespace => Caching.clear(namespace, strategy)
    )
  end
end

#cachengue_clear_by(options) ⇒ Object



34
35
36
37
38
# File 'lib/cachengue/namespace.rb', line 34

def cachengue_clear_by(options)
  Caching.clear_by(
    options.reverse_merge(namespace: self)
  )
end

#cachengue_namespace(namespace, strategy: :all) ⇒ Object



30
31
32
# File 'lib/cachengue/namespace.rb', line 30

def cachengue_namespace(namespace, strategy: :all)
  __cachengue_namespaces__[namespace.to_sym] = strategy
end

#module_cachengue(method_name, options = {}, &block) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/cachengue/namespace.rb', line 14

def module_cachengue(method_name, options = {}, &block)
  singleton_class.instance_eval do
    define_method(method_name) do |*args|
      Caching.fetch_one(self, method_name, args, options, &block)
    end
  end

  return unless options[:multi]

  singleton_class.instance_eval do
    define_method("#{method_name}_multi") do |*args|
      Caching.fetch_multi(self, method_name, args, options, &block)
    end
  end
end