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

- (Object) servers

Returns the value of attribute servers



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

def servers
  @servers
end

Instance Method Details

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



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

- (Object) append(key, value)



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

- (Object) decr(key, amount = 1)



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

- (Object) flush_all



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

def flush_all
  clear
end

- (Object) get(key, raw = false)



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

- (Object) get_multi(*keys)



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

- (Object) incr(key, amount = 1)



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

- (Object) namespace



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

def namespace
  nil
end

- (Object) reset_runtime



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

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

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



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

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

- (Object) stats



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

def stats
  {}
end