Class: CacheMigration

Inherits:
Object
  • Object
show all
Defined in:
lib/cache_migration.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(new_cache, old_cache) ⇒ CacheMigration

Returns a new instance of CacheMigration.



6
7
8
9
# File 'lib/cache_migration.rb', line 6

def initialize(new_cache, old_cache)
  @new_cache = new_cache
  @old_cache = old_cache
end

Instance Attribute Details

#new_cacheObject

Returns the value of attribute new_cache.



4
5
6
# File 'lib/cache_migration.rb', line 4

def new_cache
  @new_cache
end

#old_cacheObject

Returns the value of attribute old_cache.



4
5
6
# File 'lib/cache_migration.rb', line 4

def old_cache
  @old_cache
end

Instance Method Details

#cleanup(options = nil) ⇒ Object



63
64
65
66
# File 'lib/cache_migration.rb', line 63

def cleanup(options = nil)
  @new_cache.cleanup(options)
  @old_cache.cleanup(options)
end

#clear(options = nil) ⇒ Object



58
59
60
61
# File 'lib/cache_migration.rb', line 58

def clear(options = nil)
  @new_cache.clear(options)
  @old_cache.clear(options)
end

#decrement(name, amount = 1, options = nil) ⇒ Object



73
74
75
76
# File 'lib/cache_migration.rb', line 73

def decrement(name, amount = 1, options = nil)
  @new_cache.decrement(name, amount, options)
  @old_cache.decrement(name, amount, options)
end

#delete(name, options = nil) ⇒ Object



39
40
41
42
# File 'lib/cache_migration.rb', line 39

def delete(name, options=nil)
  @new_cache.delete(name, options)
  @old_cache.delete(name, options)
end

#delete_matched(matcher, options = nil) ⇒ Object



78
79
80
81
# File 'lib/cache_migration.rb', line 78

def delete_matched(matcher, options = nil)
  @new_cache.delete_matched(matcher, options)
  @old_cache.delete_matched(matcher, options)
end

#exist?(name, options = nil) ⇒ Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/cache_migration.rb', line 35

def exist?(name, options=nil)
  @new_cache.exist?(name, options) || @old_cache.exist?(name, options)
end

#fetch(name, options = nil) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/cache_migration.rb', line 11

def fetch(name, options=nil)
  @new_cache.fetch(name, options) do
    @old_cache.fetch(name, options) do
      yield
    end
  end
end

#fetch_multi(*names, &proc) ⇒ Object



52
53
54
55
56
# File 'lib/cache_migration.rb', line 52

def fetch_multi(*names, &proc)
  @new_cache.fetch_multi(*names) do |key|
    @old_cache.fetch(key, &proc)
  end
end

#increment(name, amount = 1, options = nil) ⇒ Object



68
69
70
71
# File 'lib/cache_migration.rb', line 68

def increment(name, amount = 1, options = nil)
  @new_cache.increment(name, amount, options)
  @old_cache.increment(name, amount, options)
end

#read(name, options = nil) ⇒ Object



19
20
21
22
23
24
25
26
27
28
# File 'lib/cache_migration.rb', line 19

def read(name, options=nil)
  value = @new_cache.read(name, options)
  if !value
    value = @old_cache.read(name, options)
    if value
      @new_cache.write(name, value, options)
    end
  end
  value
end

#read_multi(*names) ⇒ Object



44
45
46
47
48
49
50
# File 'lib/cache_migration.rb', line 44

def read_multi(*names)
  @new_cache.read_multi(*names).tap do |result|
    if result.length < names.length
      result.reverse_merge!(@old_cache.read_multi(*names))
    end
  end
end

#write(name, value, options = nil) ⇒ Object



30
31
32
33
# File 'lib/cache_migration.rb', line 30

def write(name, value, options=nil)
  @new_cache.write(name, value, options)
  @old_cache.write(name, value, options)
end