lib/flexirest/caching.rb in flexirest-1.11.0 vs lib/flexirest/caching.rb in flexirest-1.11.1
- old
+ new
@@ -72,10 +72,17 @@
Flexirest::Logger.debug " \033[1;4;32m#{Flexirest.name}\033[0m #{key} - Writing to cache" unless quiet
cached_response = CachedResponse.new(status:response.status, result:result, response_headers: headers)
cached_response.etag = "#{headers[:etag]}" if headers[:etag]
cached_response.expires = Time.parse(headers[:expires]) rescue nil if headers[:expires]
if cached_response.etag.present? || cached_response.expires
- cache_store.write(key, Marshal.dump(cached_response), {})
+ options = {}
+ if cached_response.expires.present?
+ exp_in_seconds = cached_response.expires.utc - Time.now.utc
+ return unless exp_in_seconds.positive?
+
+ options[:expires_in] = exp_in_seconds
+ end
+ cache_store.write(key, Marshal.dump(cached_response), options)
end
end
end
end