socketry/async-http-cache

Validate behaviour of cache

Opened this issue · 1 comments

require 'falcon/command'
Async do
	endpoint = Falcon::Endpoint.parse("https://localhost:9293")
	app = lambda{|env| [200, {}, ["Hello World #{rand}"]]}
	middleware = Falcon::Server.middleware(app)
	Async::HTTP::Server.new(middleware, endpoint).run
end

When reloading the page, the cache hit occurs and the random number is unchanged.

cc @tadman

We should augment the following code with comments directly to the RFC specification:

def call(request)
key = self.key(request)
cache_control = request.headers[CACHE_CONTROL]
unless cache_control&.no_cache?
if response = @store.lookup(key, request)
Async.logger.debug(self) {"Cache hit for #{key}..."}
@count += 1
# Return the cached response:
return response
end
end
unless cache_control&.no_store?
if cacheable?(request)
return wrap(key, request, super)
end
end
return super
end