Class: Cash::LocalBuffer

Inherits:
Object
  • 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.



24
25
26
27
# File 'lib/cash/local.rb', line 24

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



55
56
57
# File 'lib/cash/local.rb', line 55

def method_missing(method, *args, &block)
  @remote_cache.send(method, *args, &block)
end

Instance Method Details

#add(key, value, *options) ⇒ Object



42
43
44
45
46
47
48
# File 'lib/cash/local.rb', line 42

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



50
51
52
53
# File 'lib/cash/local.rb', line 50

def delete(key, *options)
  @remote_cache.delete(key, *options)
  @local_cache.delete(key)
end

#get(key, *options) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/cash/local.rb', line 29

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



37
38
39
40
# File 'lib/cash/local.rb', line 37

def set(key, value, *options)
  @remote_cache.set(key, value, *options)
  @local_cache[key] = value
end