background:
GET access an application, when the contents are generally not changing all the time, how to obtain the content of the response speed when the next person had requested, and can be identified when the contents are changed.
Cache done at the application layer is one way, but still the whole Body to respond to the client, not to reduce bandwidth consumption, only reduce CPU, DB consumption.
HTTP Cache is to solve this problem, the same as the second request is no longer reaches the rear end, specific support by the standard HTTP protocol.
After the request process using HTTP Cache two modes can be seen in this illustration HTTP Caching: https://tomayko.com/blog/2008/things-caches-do
Another way to mention here HTTP Gateway Cache, the Client and is completely independent open Application, equivalent to an intermediate layer, receiving client requests, receives and sends the response back-end client.
HTTP gateway cache program has Varnish, Squid.
HTTP Cache Cache provides a common four head caching is enabled, only work in safe methods GET, HEAD,
Cache-Control
Expires
ETag (entity-tag mean)
Last-Modified
The first two ways can be used to set the cache expiration time, after two ways can be used to verify that the client cache has expired.
Cache expiration and cache validation can be combined to achieve the best results.
HTTP Cache in use in Laravel
https://laravel.com/docs/6.x/responses#attaching-headers-to-responses,
The first way is by Response components API, by giving additional Response Header information, header () and withHeaders () two methods.
The second way is to use Cache Control Middleware to quickly set up a set of routing cache-control, etag, last_modified and so on.
# routeMiddleware
'cache.headers' => \Illuminate\Http\Middleware\SetCacheHeaders::class
# Apply example
Route::middleware('cache.headers:private;max_age=60')
Symfony HTTP Cache:https://symfony.com/doc/current/http_cache.html
Symfony HTTP Cache Validation:https://symfony.com/doc/current/http_cache/validation.html
HTTP/1.1 RFC, HTTP Caches and associated header fields:https://tools.ietf.org/html/rfc7234
HTTP/1.1 RFC, HTTP Conditional Request:https://tools.ietf.org/html/rfc7234
cache-control private:https://baike.baidu.com/item/Cache-control/1885913