Class: ActiveSupport::Cache::TTLedMemCacheStore
- Inherits:
-
MemCacheStore
- Object
- MemCacheStore
- ActiveSupport::Cache::TTLedMemCacheStore
- Defined in:
- lib/that_old_cache/ttled_mem_cache_store.rb
Instance Method Summary collapse
-
#expired?(key) ⇒ Boolean
only works for TTLed keys.
-
#read(key, options = nil) ⇒ Object
Adds the following option: :valid_for => true :raw is not supported with :valid_for.
-
#ttl(key) ⇒ Object
only works for TTLed keys.
-
#write(key, value, options = nil) ⇒ Object
Adds the following option: :valid_for => number of seconds from now that the cache with “expire” :raw is not supported with :valid_for.
Instance Method Details
#expired?(key) ⇒ Boolean
only works for TTLed keys
32 33 34 35 36 37 38 |
# File 'lib/that_old_cache/ttled_mem_cache_store.rb', line 32 def expired?(key) begin ttl(key) < Time.now.to_i rescue NoMethodError false end end |
#read(key, options = nil) ⇒ Object
Adds the following option:
:valid_for => true
:raw is not supported with :valid_for
22 23 24 25 26 27 28 29 |
# File 'lib/that_old_cache/ttled_mem_cache_store.rb', line 22 def read(key, = nil) if && .delete(:valid_for) .delete(:raw) parse(super)[:data] rescue nil else super end end |
#ttl(key) ⇒ Object
only works for TTLed keys
41 42 43 |
# File 'lib/that_old_cache/ttled_mem_cache_store.rb', line 41 def ttl(key) parse(read(key))[:ttl] rescue nil end |
#write(key, value, options = nil) ⇒ Object
Adds the following option:
:valid_for => number of seconds from now that the cache with "expire"
:raw is not supported with :valid_for
10 11 12 13 14 15 16 17 |
# File 'lib/that_old_cache/ttled_mem_cache_store.rb', line 10 def write(key, value, = nil) if && [:valid_for] .delete(:raw) super(key, encode({ :data => value, :ttl => time_for(.delete(:valid_for)) }), ) else super end end |