Class: Undo::Storage::RailsCache

Inherits:
Adapter
  • Object
show all
Defined in:
lib/undo/storage/rails_cache.rb

Instance Method Summary collapse

Constructor Details

#initialize(cache = nil, options = {}) ⇒ RailsCache



6
7
8
9
10
11
# File 'lib/undo/storage/rails_cache.rb', line 6

def initialize(cache = nil, options = {})
  @cache = cache
  @cache ||= Rails.cache if defined? Rails

  super options
end

Instance Method Details

#delete(uuid, options = {}) ⇒ Object



24
25
26
# File 'lib/undo/storage/rails_cache.rb', line 24

def delete(uuid, options = {})
  cache.delete uuid, adapter_options(options)
end

#fetch(uuid, options = {}) ⇒ Object

Raises:

  • (KeyError)


19
20
21
22
# File 'lib/undo/storage/rails_cache.rb', line 19

def fetch(uuid, options = {})
  raise KeyError, "key #{uuid} not found" unless cache.exist? uuid
  unpack cache.read uuid, adapter_options(options)
end

#store(uuid, object, options = {}) ⇒ Object



13
14
15
16
17
# File 'lib/undo/storage/rails_cache.rb', line 13

def store(uuid, object, options = {})
  cache.write uuid,
              pack(object),
              adapter_options(options)
end