Class: ActiveCache::Store::DalliStore

Inherits:
AbstractStore show all
Defined in:
lib/active_cache/store/dalli_store.rb

Class Method Summary collapse

Class Method Details

.dcObject



7
8
9
# File 'lib/active_cache/store/dalli_store.rb', line 7

def self.dc
  @@dc ||= Dalli::Client.new
end

.expire(key) ⇒ Object



28
29
30
# File 'lib/active_cache/store/dalli_store.rb', line 28

def self.expire(key)
  dc.delete(key)
end

.read(key) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/active_cache/store/dalli_store.rb', line 11

def self.read(key)
  page = dc.get(key)
  case 
    when page.nil?
      nil
    when page[:expires].nil?
      page[:content]
    else
      page[:expires] > Time.now ? page[:content] : nil
  end
end

.write(key, value, expire = nil) ⇒ Object



23
24
25
26
# File 'lib/active_cache/store/dalli_store.rb', line 23

def self.write(key, value, expire = nil)
  expire = Time.now + expire unless expire.nil?
  dc.set(key,{:expires => expire, :content => value})
end