Class: Sequel::Plugins::Cacheable::Driver
- Inherits:
-
Object
- Object
- Sequel::Plugins::Cacheable::Driver
show all
- Defined in:
- lib/sequel-cacheable/driver.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(store, pack_lib = MessagePackPacker) ⇒ Driver
Returns a new instance of Driver.
19
20
21
22
|
# File 'lib/sequel-cacheable/driver.rb', line 19
def initialize(store, pack_lib = MessagePackPacker)
@store = store
@packer = pack_lib
end
|
Class Method Details
.factory(*args) ⇒ Object
6
7
8
9
10
11
12
13
14
15
16
17
|
# File 'lib/sequel-cacheable/driver.rb', line 6
def self.factory(*args)
case args[0].class.name
when 'Memcache'
MemcacheDriver.new(*args)
when 'Dalli::Client'
DalliDriver.new(*args)
when 'Redis'
RedisDriver.new(*args)
else
Driver.new(*args)
end
end
|
Instance Method Details
#del(key) ⇒ Object
37
38
39
40
41
|
# File 'lib/sequel-cacheable/driver.rb', line 37
def del(key)
@store.del(key)
return nil
end
|
#expire(key, time) ⇒ Object
43
44
45
|
# File 'lib/sequel-cacheable/driver.rb', line 43
def expire(key, time)
@store.expire(key, time)
end
|
#fetch(key, ttl = nil, &block) ⇒ Object
47
48
49
|
# File 'lib/sequel-cacheable/driver.rb', line 47
def fetch(key, ttl = nil, &block)
get(key) || set(key, block.call, ttl)
end
|
#get(key) ⇒ Object
24
25
26
27
28
|
# File 'lib/sequel-cacheable/driver.rb', line 24
def get(key)
val = @store.get(key)
return val.nil? || val.empty? ? nil : @packer.unpack(val)
end
|
#set(key, val, expire = nil) ⇒ Object
30
31
32
33
34
35
|
# File 'lib/sequel-cacheable/driver.rb', line 30
def set(key, val, expire = nil)
@store.set(key, @packer.pack(val))
expire(key, expire) unless expire.nil?
return val
end
|