module RecordCache::Base::ClassMethods

Public Instance Methods

cache_records(options = {}) click to toggle source

Cache the instances of this model generic options:

:store => the cache store for the instances, e.g. :memory_store, :dalli_store* (default: Rails.cache)
          or one of the store ids defined using +RecordCache::Base.register_store+
:key   => provide a unique shorter key to limit the cache key length (default: model.name)

cache strategy specific options:

:index => one or more attributes (Symbols) for which the ids are cached for the value of the attribute

Hints:

- Dalli is a high performance pure Ruby client for accessing memcached servers, see https://github.com/mperham/dalli
- use :store => :memory_store in case all records can easily fit in server memory
- use :index => :account_id in case the records are (almost) always queried as a full set per account
- use :index => :person_id for aggregated has_many associations
# File lib/record_cache/base.rb, line 125
def cache_records(options = {})
  unless @rc_dispatcher
    @rc_dispatcher = RecordCache::Dispatcher.new(self)
    # Callback for Data Store specific initialization
    record_cache_init

    class << self
      alias_method_chain :inherited, :record_cache
    end
  end
  # parse the requested strategies from the given options
  @rc_dispatcher.parse(options)
end
inherited_with_record_cache(subclass) click to toggle source
# File lib/record_cache/base.rb, line 149
def inherited_with_record_cache(subclass)
  class << subclass
    def record_cache
      self.superclass.record_cache
    end
  end
  inherited_without_record_cache(subclass)
end
record_cache() click to toggle source

Returns the RecordCache (class) instance

# File lib/record_cache/base.rb, line 145
def record_cache
  @rc_dispatcher
end
record_cache?() click to toggle source

Returns true if record cache is defined and active for this class

# File lib/record_cache/base.rb, line 140
def record_cache?
  record_cache && record_cache.instance_variable_get('@base') == self && RecordCache::Base.status == RecordCache::ENABLED
end