Method: Exchange::Cache::Redis#cached
- Defined in:
- lib/exchange/cache/redis.rb
#cached(api, opts = {}) { ... } ⇒ Object
returns either cached data from the redis client or calls the block and caches it in redis. This method has to be the same in all the cache classes in order for the configuration binding to work
46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/exchange/cache/redis.rb', line 46 def cached api, opts={}, &block if result = client.get(key(api, opts)) result = opts[:plain] ? result : result.decachify else result = super if result && !result.to_s.empty? client.set key(api, opts), result.cachify client.expire key(api, opts), config.expire == :daily ? 86400 : 3600 end end result end |