./lib/lux/cache/cache.rb in lux-fw-0.1.17 vs ./lib/lux/cache/cache.rb in lux-fw-0.1.35

- old
+ new

@@ -33,17 +33,24 @@ def delete key, data=nil @@server.delete(key) end - def fetch key, ttl=nil, log=true - ttl = ttl.to_i if ttl - @@server.delete key if Lux.page && Lux.page.no_cache? + def fetch key, opts={} + opts = { ttl: opts } unless opts.is_a?(Hash) + opts = opts.to_opts!(:ttl, :log, :force) - Lux.log " Cache.fetch.get #{key} (ttl: #{ttl.or(:nil)})" if log - data = @@server.fetch key, ttl do + opts.ttl = opts.ttl.to_i if opts.ttl + opts.log ||= true if opts.log.nil? + opts.force ||= true if opts.force.nil? + + @@server.delete key if Lux.page && opts.force && Lux.page.no_cache? + + Lux.log " Cache.fetch.get #{key} (ttl: #{opts.ttl.or(:nil)})".green if opts.log + + data = @@server.fetch key, opts.ttl do data = yield - Lux.log " Cache.fetch.SET #{key} len:#{data.to_s.length}" if log + Lux.log " Cache.fetch.SET #{key} len:#{data.to_s.length}" if opts.log data end data end