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.



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

#method_missing(method, *args, &block) ⇒ Object (private)



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

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



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

#delete(key, *options) ⇒ Object



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

#get(key, *options) ⇒ Object



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

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



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