Method: Cash::Accessor::ClassMethods#incr

Defined in:
lib/cash/accessor.rb

#incr(key, delta = 1, ttl = nil) ⇒ Object



52
53
54
55
56
57
58
# File 'lib/cash/accessor.rb', line 52

def incr(key, delta = 1, ttl = nil)
  ttl ||= cache_config.ttl
  repository.incr(cache_key = cache_key(key), delta) || begin
    repository.add(cache_key, (result = yield).to_s, ttl, true) { repository.incr(cache_key) }
    result
  end
end