Class: Castache
- Inherits:
-
Object
- Object
- Castache
- Defined in:
- lib/castache.rb,
lib/castache/version.rb
Constant Summary collapse
- VERSION =
"0.0.4"
Class Attribute Summary collapse
-
.redis ⇒ Object
Returns the value of attribute redis.
Class Method Summary collapse
Class Attribute Details
.redis ⇒ Object
Returns the value of attribute redis.
6 7 8 |
# File 'lib/castache.rb', line 6 def redis @redis end |
Class Method Details
.fetch(key, &block) ⇒ Object
8 9 10 11 12 13 |
# File 'lib/castache.rb', line 8 def fetch (key, &block) unless object = get(key) object = set(key, block.call) if block_given? end object end |
.get(key) ⇒ Object
19 20 21 22 23 |
# File 'lib/castache.rb', line 19 def get(key) if value = redis.get(key) Marshal.load(value) end end |
.mget(keys) ⇒ Object
25 26 27 28 |
# File 'lib/castache.rb', line 25 def mget(keys) raise TypeError, "keys should be an array" unless keys.is_a? Array redis.mget(keys).map {|item| Marshal.load(item) unless item.nil? } end |
.set(key, object) ⇒ Object
15 16 17 |
# File 'lib/castache.rb', line 15 def set(key, object) object if redis.set(key, Marshal.dump(object)) end |