Class: KvCache::Store
- Inherits:
-
Object
- Object
- KvCache::Store
- Defined in:
- lib/kv_cache/store.rb
Class Method Summary collapse
-
.call(key, expire_time) ⇒ Object
call yield if key is not exist.
- .defalt_storer ⇒ Object
-
.delete(*keys) ⇒ Object
delete key.
-
.storer ⇒ Object
like Dalli for memcached #get, #set is Necessary!!.
-
.storer=(_storer) ⇒ Object
opts = { :namespace => “app_v2”, :compress => true } KvCache::Store.storer = Dalli::Client.new(‘127.0.0.1:11211’, opts).
Class Method Details
.call(key, expire_time) ⇒ Object
call yield if key is not exist
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/kv_cache/store.rb', line 8 def call(key,expire_time) res = storer.get(key) return res if res res = (yield rescue nil) storer.set(key, res, expire_time) res end |
.defalt_storer ⇒ Object
30 31 32 33 |
# File 'lib/kv_cache/store.rb', line 30 def defalt_storer opts = { :namespace => "app_v1", :compress => true } Dalli::Client.new('127.0.0.1:11211', opts) end |
.delete(*keys) ⇒ Object
delete key
20 21 22 |
# File 'lib/kv_cache/store.rb', line 20 def delete(*keys) keys.each { |e| storer.delete(e) } end |
.storer ⇒ Object
like Dalli for memcached #get, #set is Necessary!!
26 27 28 |
# File 'lib/kv_cache/store.rb', line 26 def storer @@_storer ||= defalt_storer end |
.storer=(_storer) ⇒ Object
opts = { :namespace => “app_v2”, :compress => true } KvCache::Store.storer = Dalli::Client.new(‘127.0.0.1:11211’, opts)
37 38 39 |
# File 'lib/kv_cache/store.rb', line 37 def storer=(_storer) @@_storer = _storer end |