lib/twitter_friendly/cache.rb in twitter_friendly-0.2.1 vs lib/twitter_friendly/cache.rb in twitter_friendly-0.3.0

- old
+ new

@@ -12,36 +12,33 @@ path = options[:cache_dir] || File.join('.twitter_friendly', 'cache') FileUtils.mkdir_p(path) unless File.exists?(path) @client = ::ActiveSupport::Cache::FileStore.new(path, options) end - def fetch(method, user, options = {}, &block) - key = CacheKey.gen(method, user, options.except(:args)) - super_operation = options[:args].length >= 2 && options[:args][1][:super_operation] - + # @param key [String] + # + # @option serialize_options [Array] :args + def fetch(key, serialize_options, &block) block_result = nil - blk = + yield_and_encode = Proc.new do block_result = yield - encode(block_result, args: options[:args]) + encode(block_result, serialize_options) end - fetch_result = - if super_operation - @client.fetch(key, tf_super_operation: super_operation, &blk) - else - @client.fetch(key, &blk) - end + fetch_result = @client.fetch(key, &yield_and_encode) - block_result ? block_result : decode(fetch_result, args: options[:args]) + block_result || decode(fetch_result, serialize_options) end private + # @option options [Array] :args def encode(obj, options) Serializer.encode(obj, options) end + # @option options [Array] :args def decode(str, options) Serializer.decode(str, options) end end end