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.



26
27
28
29
# File 'lib/cash/local.rb', line 26

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 (private)



59
60
61
# File 'lib/cash/local.rb', line 59

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

Instance Method Details

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



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

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



52
53
54
55
# File 'lib/cash/local.rb', line 52

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

#get(key, *options) ⇒ Object



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

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



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

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