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