Module: RedisCacheable::ActiveRecord::ClassMethods

Defined in:
lib/redis_cacheable/active_record.rb

Instance Method Summary collapse

Instance Method Details

#cache_all(options = {}) ⇒ void

This method returns an undefined value.

cache all persisted records

Parameters:

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

    pass to find_each method



21
22
23
24
25
26
27
28
29
# File 'lib/redis_cacheable/active_record.rb', line 21

def cache_all(options = {})
  find_each(options) do |record|
    record.cache_to_redis
  end

  redis do |conn|
    conn.save
  end
end

#find_from_redis(key) ⇒ ActiveRecord::Base

Returns ActiveRecord instantiated object.

Parameters:

  • key (Object)

Returns:

  • (ActiveRecord::Base)

    ActiveRecord instantiated object



12
13
14
15
16
# File 'lib/redis_cacheable/active_record.rb', line 12

def find_from_redis(key)
  if data = super(key)
    instantiate(data)
  end
end