Class: ActionHandle::Adapters::CacheStore
- Defined in:
- lib/action_handle/adapters/cache_store.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
Instance Method Summary collapse
- #claim(key, value, ttl) ⇒ Object
- #create(key, value, ttl) ⇒ Object
- #current?(key, value) ⇒ Boolean
- #expire(key) ⇒ Object
-
#initialize(cache = nil) ⇒ CacheStore
constructor
A new instance of CacheStore.
- #renew(key, value, ttl) ⇒ Object
- #taken?(key) ⇒ Boolean
- #value(key) ⇒ Object
Constructor Details
#initialize(cache = nil) ⇒ CacheStore
Returns a new instance of CacheStore.
8 9 10 |
# File 'lib/action_handle/adapters/cache_store.rb', line 8 def initialize(cache = nil) @client = cache end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
6 7 8 |
# File 'lib/action_handle/adapters/cache_store.rb', line 6 def client @client end |
Instance Method Details
#claim(key, value, ttl) ⇒ Object
40 41 42 43 44 |
# 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) ⇒ Object
12 13 14 15 16 |
# 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) ⇒ Boolean
30 31 32 33 34 |
# 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) ⇒ Object
46 47 48 49 50 |
# 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) ⇒ Object
18 19 20 21 22 |
# 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) ⇒ Boolean
24 25 26 27 28 |
# 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) ⇒ Object
36 37 38 |
# File 'lib/action_handle/adapters/cache_store.rb', line 36 def value(key) safely_perform { client.read(key) } end |