Class: Cash::LocalBuffer
- Inherits:
-
Object
show all
- Defined in:
- lib/cash/local.rb
Instance Method Summary
(collapse)
Constructor Details
- (LocalBuffer) initialize(remote_cache)
A new instance of LocalBuffer
39
40
41
42
|
# File 'lib/cash/local.rb', line 39
def initialize(remote_cache)
@local_cache = {}
@remote_cache = remote_cache
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
- (Object) method_missing(method, *args, &block)
72
73
74
|
# File 'lib/cash/local.rb', line 72
def method_missing(method, *args, &block)
@remote_cache.send(method, *args, &block)
end
|
Instance Method Details
- (Object) add(key, value, *options)
57
58
59
60
61
62
63
|
# File 'lib/cash/local.rb', line 57
def add(key, value, *options)
result = @remote_cache.add(key, value, *options)
if result == "STORED\r\n"
@local_cache[key] = value
end
result
end
|
- (Object) delete(key, *options)
65
66
67
68
|
# File 'lib/cash/local.rb', line 65
def delete(key, *options)
@remote_cache.delete(key, *options)
@local_cache.delete(key)
end
|
- (Object) get(key, *options)
44
45
46
47
48
49
50
|
# File 'lib/cash/local.rb', line 44
def get(key, *options)
if @local_cache.has_key?(key)
@local_cache[key]
else
@local_cache[key] = @remote_cache.get(key, *options)
end
end
|
- (Object) set(key, value, *options)
52
53
54
55
|
# File 'lib/cash/local.rb', line 52
def set(key, value, *options)
@remote_cache.set(key, value, *options)
@local_cache[key] = value
end
|