module Mobility::Plugins::Cache

Caches values fetched from the backend so subsequent fetches can be performed more quickly. The cache stores cached values in a simple hash, which is not optimal for some storage strategies, so some backends (KeyValue, Table) use a custom module by defining a method, include_cache, on the backend class.

The cache is reset when one of a set of events happens (saving, reloading, etc.). See {BackendResetter} for details.

Values are added to the cache in two ways:

  1. first read from backend

  2. any write to backend

Private Instance Methods

define_cache_hooks(klass, *reset_methods) click to toggle source

Used in ORM cache plugins

Calls superclass method
# File lib/mobility/plugins/cache.rb, line 45
def define_cache_hooks(klass, *reset_methods)
  mod = self
  private_methods = reset_methods & klass.private_instance_methods
  reset_methods.each do |method_name|
    define_method method_name do |*args|
      super(*args).tap do
        mod.names.each { |name| mobility_backends[name].clear_cache }
      end
    end
  end
  klass.class_eval { private(*private_methods) }
end
include_cache(backend_class) click to toggle source
# File lib/mobility/plugins/cache.rb, line 40
def include_cache(backend_class)
  backend_class.include BackendMethods
end