Method: MethodCacheable#cache

Defined in:
lib/method_cacheable.rb

#cacheObject #cache(options = {}) ⇒ Object #cache(cache_operation = :fetch) ⇒ Object #cache(cache_operation = :fetch, options = {}) ⇒ Object

Examples:

user = User.last
# cache
user.cache.some_method

# cache(options)
user.cache(:expires_in => 1.minutes).some_method

# cache(cache_operation)
user.cache(:fetch).some_method
user.cache(:read).some_method
user.cache(:write).some_method

# cache(cache_operation, options)
user.cache(:write, :expires_in 2.minutes).some_method

Overloads:

  • #cache(cache_operation = :fetch, options = {}) ⇒ Object

    Creates a MethodCache instance that performs the given cache operation on the method it receives

    Parameters:

    • cache_operation (Symbol) (defaults to: :fetch)

      (:fetch) The method called on the cache (:write, :read, or :fetch)

    • options (Hash) (defaults to: {})

      Optional hash that gets passed to the cache store



73
74
75
# File 'lib/method_cacheable.rb', line 73

def cache(*args)
  MethodCache.new(self, *args)
end