Class: Cash::Fake

Inherits:
HashWithIndifferentAccess
  • Object
show all
Defined in:
lib/cash/fake.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#serversObject

Returns the value of attribute servers.



3
4
5
# File 'lib/cash/fake.rb', line 3

def servers
  @servers
end

Instance Method Details

#add(key, value, ttl = 0, raw = false) ⇒ Object



39
40
41
42
43
44
# File 'lib/cash/fake.rb', line 39

def add(key, value, ttl = 0, raw = false)
  return false if self.has_key?(key)

  self[key] = marshal(value, raw)
  true
end

#append(key, value) ⇒ Object



46
47
48
# File 'lib/cash/fake.rb', line 46

def append(key, value)
  set(key, get(key, true).to_s + value.to_s, nil, true)
end

#decr(key, amount = 1) ⇒ Object



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

def decr(key, amount = 1)
  if self.has_key?(key)
    self[key] = (self[key].to_i - amount).to_s
    self[key].to_i
  end
end

#flush_allObject



54
55
56
# File 'lib/cash/fake.rb', line 54

def flush_all
  clear
end

#get(key, raw = false) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/cash/fake.rb', line 13

def get(key, raw = false)
  if raw
    self[key]
  else
    if self.has_key?(key)
      Marshal.load(self[key])
    else
      nil
    end
  end
end

#get_multi(*keys) ⇒ Object



5
6
7
# File 'lib/cash/fake.rb', line 5

def get_multi(*keys)
  slice(*keys).collect { |k,v| [k, Marshal.load(v)] }.to_hash
end

#incr(key, amount = 1) ⇒ Object



25
26
27
28
29
30
# File 'lib/cash/fake.rb', line 25

def incr(key, amount = 1)
  if self.has_key?(key)
    self[key] = (self[key].to_i + amount).to_s
    self[key].to_i
  end
end

#namespaceObject



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

def namespace
  nil
end

#reset_runtimeObject



62
63
64
# File 'lib/cash/fake.rb', line 62

def reset_runtime
  [0, Hash.new(0)]
end

#set(key, value, ttl = 0, raw = false) ⇒ Object



9
10
11
# File 'lib/cash/fake.rb', line 9

def set(key, value, ttl = 0, raw = false)
  self[key] = marshal(value, raw)
end

#statsObject



58
59
60
# File 'lib/cash/fake.rb', line 58

def stats
  {}
end