class Excursion::Datastores::ActiveRecordWithMemcache

Public Class Methods

new(server) click to toggle source
# File lib/excursion/datastores/active_record_with_memcache.rb, line 41
def initialize(server)
  @model = Excursion::Datastores::ActiveRecord.new
  @cache = Excursion::Datastores::Memcache.new(server)
end

Public Instance Methods

all() click to toggle source
# File lib/excursion/datastores/active_record_with_memcache.rb, line 31
def all
  hash = @cache.all
  return hash unless hash.nil? || hash.empty?
  @model.all
rescue Dalli::RingError => e
  rescue_from_dalli_ring_error(e) && retry
end
delete(key) click to toggle source
# File lib/excursion/datastores/active_record_with_memcache.rb, line 25
def delete(key)
  @model.delete(key)
  @cache.delete(key)
end
Also aliased as: unset
get(key)
Alias for: read
read(key) click to toggle source
# File lib/excursion/datastores/active_record_with_memcache.rb, line 8
def read(key)
  value = @cache.read(key)
  return value unless value.nil?
  
  value = @model.read(key)
  @cache.write(key, value) unless value.nil?

  value
end
Also aliased as: get
set(key, value)
Alias for: write
unset(key)
Alias for: delete
write(key, value) click to toggle source
# File lib/excursion/datastores/active_record_with_memcache.rb, line 19
def write(key, value)
  @model.write(key, value)
  @cache.write(key, value)
end
Also aliased as: set