Class: Sequel::Plugins::QueryCache::Driver
- Inherits:
-
Object
- Object
- Sequel::Plugins::QueryCache::Driver
show all
- Defined in:
- lib/sequel-query-cache/driver.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(store, opts = {}) ⇒ Driver
Returns a new instance of Driver.
20
21
22
23
|
# File 'lib/sequel-query-cache/driver.rb', line 20
def initialize(store, opts={})
@store = store
@serializer = opts[:serializer] || _default_serializer
end
|
Instance Attribute Details
#serializer ⇒ Object
Returns the value of attribute serializer.
18
19
20
|
# File 'lib/sequel-query-cache/driver.rb', line 18
def serializer
@serializer
end
|
#store ⇒ Object
Returns the value of attribute store.
18
19
20
|
# File 'lib/sequel-query-cache/driver.rb', line 18
def store
@store
end
|
Class Method Details
.from_store(store, opts = {}) ⇒ Object
5
6
7
8
9
10
11
12
13
14
15
16
|
# File 'lib/sequel-query-cache/driver.rb', line 5
def self.from_store(store, opts={})
case store.class.name
when 'Memcache'
require 'sequel-query-cache/driver/memcache'
MemcacheDriver.new(store, opts)
when 'Dalli::Client'
require 'sequel-query-cache/driver/dalli'
DalliDriver.new(store, opts)
else
Driver.new(store, opts)
end
end
|
Instance Method Details
#del(key) ⇒ Object
36
37
38
39
|
# File 'lib/sequel-query-cache/driver.rb', line 36
def del(key)
store.del(key)
nil
end
|
#expire(key, time) ⇒ Object
41
42
43
|
# File 'lib/sequel-query-cache/driver.rb', line 41
def expire(key, time)
store.expire(key, time)
end
|
#get(key) ⇒ Object
25
26
27
28
|
# File 'lib/sequel-query-cache/driver.rb', line 25
def get(key)
val = store.get(key)
val ? serializer.deserialize(val) : nil
end
|
#set(key, val, opts = {}) ⇒ Object
30
31
32
33
34
|
# File 'lib/sequel-query-cache/driver.rb', line 30
def set(key, val, opts={})
store.set(key, serializer.serialize(val))
expire(key, opts[:ttl]) unless opts[:ttl].nil?
val
end
|