Class: CacheAdvance::CachedKeyList

Inherits:
Object
  • Object
show all
Defined in:
lib/cache_advance/cached_key_list.rb

Instance Method Summary collapse

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_keysObject



7
8
9
# File 'lib/cache_advance/cached_key_list.rb', line 7

def all_keys
  key_list.keys
end

#clearObject



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