Class: CacheMigration
- Inherits:
-
Object
- Object
- CacheMigration
- Defined in:
- lib/cache_migration.rb
Instance Attribute Summary collapse
-
#new_cache ⇒ Object
Returns the value of attribute new_cache.
-
#old_cache ⇒ Object
Returns the value of attribute old_cache.
Instance Method Summary collapse
- #cleanup(options = nil) ⇒ Object
- #clear(options = nil) ⇒ Object
- #decrement(name, amount = 1, options = nil) ⇒ Object
- #delete(name, options = nil) ⇒ Object
- #delete_matched(matcher, options = nil) ⇒ Object
- #exist?(name, options = nil) ⇒ Boolean
- #fetch(name, options = nil) ⇒ Object
- #fetch_multi(*names, &proc) ⇒ Object
- #increment(name, amount = 1, options = nil) ⇒ Object
-
#initialize(new_cache, old_cache) ⇒ CacheMigration
constructor
A new instance of CacheMigration.
- #read(name, options = nil) ⇒ Object
- #read_multi(*names) ⇒ Object
- #write(name, value, options = nil) ⇒ Object
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_cache ⇒ Object
Returns the value of attribute new_cache.
4 5 6 |
# File 'lib/cache_migration.rb', line 4 def new_cache @new_cache end |
#old_cache ⇒ Object
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( = nil) @new_cache.cleanup() @old_cache.cleanup() end |
#clear(options = nil) ⇒ Object
58 59 60 61 |
# File 'lib/cache_migration.rb', line 58 def clear( = nil) @new_cache.clear() @old_cache.clear() end |
#decrement(name, amount = 1, options = nil) ⇒ Object
73 74 75 76 |
# File 'lib/cache_migration.rb', line 73 def decrement(name, amount = 1, = nil) @new_cache.decrement(name, amount, ) @old_cache.decrement(name, amount, ) end |
#delete(name, options = nil) ⇒ Object
39 40 41 42 |
# File 'lib/cache_migration.rb', line 39 def delete(name, =nil) @new_cache.delete(name, ) @old_cache.delete(name, ) end |
#delete_matched(matcher, options = nil) ⇒ Object
78 79 80 81 |
# File 'lib/cache_migration.rb', line 78 def delete_matched(matcher, = nil) @new_cache.delete_matched(matcher, ) @old_cache.delete_matched(matcher, ) end |
#exist?(name, options = nil) ⇒ Boolean
35 36 37 |
# File 'lib/cache_migration.rb', line 35 def exist?(name, =nil) @new_cache.exist?(name, ) || @old_cache.exist?(name, ) end |
#fetch(name, options = nil) ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/cache_migration.rb', line 11 def fetch(name, =nil) @new_cache.fetch(name, ) do @old_cache.fetch(name, ) 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, = nil) @new_cache.increment(name, amount, ) @old_cache.increment(name, amount, ) 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, =nil) value = @new_cache.read(name, ) if !value value = @old_cache.read(name, ) if value @new_cache.write(name, value, ) 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, =nil) @new_cache.write(name, value, ) @old_cache.write(name, value, ) end |