class ActionHandle::Adapters::CacheStore
Attributes
client[R]
Public Class Methods
new(cache = nil)
click to toggle source
# File lib/action_handle/adapters/cache_store.rb, line 8 def initialize(cache = nil) @client = cache end
Public Instance Methods
claim(key, value, ttl)
click to toggle source
# File lib/action_handle/adapters/cache_store.rb, line 40 def claim(key, value, ttl) perform_with_expectation('OK') do client.write(key, value, expires_in: ttl) end end
create(key, value, ttl)
click to toggle source
# File lib/action_handle/adapters/cache_store.rb, line 12 def create(key, value, ttl) perform_with_expectation('OK') do client.write(key, value, expires_in: ttl) unless taken?(key) end end
current?(key, value)
click to toggle source
# File lib/action_handle/adapters/cache_store.rb, line 30 def current?(key, value) perform_with_expectation(value.to_s) do client.read(key) end end
expire(key)
click to toggle source
# File lib/action_handle/adapters/cache_store.rb, line 46 def expire(key) perform_with_expectation(true) do client.delete(key).to_i > 0 end end
renew(key, value, ttl)
click to toggle source
# File lib/action_handle/adapters/cache_store.rb, line 18 def renew(key, value, ttl) perform_with_expectation('OK') do client.write(key, value, expires_in: ttl) if current?(key, value) end end
taken?(key)
click to toggle source
# File lib/action_handle/adapters/cache_store.rb, line 24 def taken?(key) perform_with_expectation(true) do client.exist?(key) end end
value(key)
click to toggle source
# File lib/action_handle/adapters/cache_store.rb, line 36 def value(key) safely_perform { client.read(key) } end