Class: CacheAdvance::CachedKeyList
- Inherits:
-
Object
- Object
- CacheAdvance::CachedKeyList
- Defined in:
- lib/cache_advance/cached_key_list.rb
Instance Method Summary collapse
- #add_key(key) ⇒ Object
- #all_keys ⇒ Object
- #clear ⇒ Object
- #delete_key(key) ⇒ Object
-
#initialize(store, cache_key, expiration_time = nil) ⇒ CachedKeyList
constructor
A new instance of CachedKeyList.
Constructor Details
#initialize(store, cache_key, expiration_time = nil) ⇒ CachedKeyList
Returns a new instance of CachedKeyList.
3 4 5 |
# File 'lib/cache_advance/cached_key_list.rb', line 3 def initialize(store, cache_key, expiration_time=nil) @store, @cache_key, @expiration_time = store, cache_key, expiration_time end |
Instance Method Details
#add_key(key) ⇒ Object
11 12 13 14 15 16 17 18 19 |
# File 'lib/cache_advance/cached_key_list.rb', line 11 def add_key(key) Lock.new(@store).execute_locked(@cache_key) do data = key_list unless data.has_key?(key) data[key] = @expiration_time.nil? ? nil : Time.now + @expiration_time @store.set(@cache_key, data) end end end |
#all_keys ⇒ Object
7 8 9 |
# File 'lib/cache_advance/cached_key_list.rb', line 7 def all_keys key_list.keys end |
#clear ⇒ Object
31 32 33 |
# File 'lib/cache_advance/cached_key_list.rb', line 31 def clear @store.set(@cache_key, {}) end |
#delete_key(key) ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'lib/cache_advance/cached_key_list.rb', line 21 def delete_key(key) Lock.new(@store).execute_locked(@cache_key) do data = key_list if data.has_key?(key) data.delete(key) @store.set(@cache_key, data) end end end |