Class: RCache::Cache
- Inherits:
-
Object
- Object
- RCache::Cache
- Defined in:
- lib/r_cache.rb
Overview
Your code goes hereā¦
Constant Summary collapse
- @@redis =
Redis.new
Instance Attribute Summary collapse
-
#updater ⇒ Object
Returns the value of attribute updater.
Instance Method Summary collapse
- #delete(names) ⇒ Object
-
#expired?(expiry) ⇒ Boolean
s.
- #get(name, keys = nil) ⇒ Object
- #store(name, hash) ⇒ Object
- #update(name) ⇒ Object
Instance Attribute Details
#updater ⇒ Object
Returns the value of attribute updater.
37 38 39 |
# File 'lib/r_cache.rb', line 37 def updater @updater end |
Instance Method Details
#delete(names) ⇒ Object
71 72 73 |
# File 'lib/r_cache.rb', line 71 def delete names @@redis.del *names end |
#expired?(expiry) ⇒ Boolean
s
39 40 41 |
# File 'lib/r_cache.rb', line 39 def expired? expiry # s Time.now.to_i >= expiry.to_i end |
#get(name, keys = nil) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/r_cache.rb', line 48 def get name, keys=nil unless keys obj = @@redis.hgetall name else obj = @@redis.hmget name, *keys end puts 'about to update' obj = update(name) if obj.nil? || ( Config.keys[:ttl] && expired?(obj['expiry']) ) # if nil or expired # refresh obj end |
#store(name, hash) ⇒ Object
43 44 45 46 |
# File 'lib/r_cache.rb', line 43 def store name, hash add_expiry(hash) if Config.keys[:ttl] @@redis.hmset name, *hash.to_a end |
#update(name) ⇒ Object
62 63 64 65 66 67 68 69 |
# File 'lib/r_cache.rb', line 62 def update name puts 'updating' delete [name] n_obj = @updater.call(name) store name, n_obj #binding.pry get name end |