From e1a5cd0c42bea63181a98a06fce95f32993c2f0a Mon Sep 17 00:00:00 2001 From: shoully Date: Sat, 20 Dec 2014 06:03:36 -0800 Subject: [PATCH] Created HTTP Caching (markdown) --- HTTP-Caching.md | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 HTTP-Caching.md diff --git a/HTTP-Caching.md b/HTTP-Caching.md new file mode 100644 index 0000000..a3f2367 --- /dev/null +++ b/HTTP-Caching.md @@ -0,0 +1,26 @@ +Flight provides built-in support for HTTP level caching. If the caching condition is met, +Flight will return an HTTP `304 Not Modified` response. The next time the client requests the same resource, +they will be prompted to use their locally cached version. + +## Last-Modified + +You can use the `lastModified` method and pass in a UNIX timestamp to set the date and time a page was last modified. +The client will continue to use their cache until the last modified value is changed. + + Flight::route('/news', function(){ + Flight::lastModified(1234567890); + echo 'This content will be cached.'; + }); + +## ETag + +ETag caching is similar to Last-Modified, except you can specify any id you want for the resource: + + Flight::route('/news', function(){ + Flight::etag('my-unique-id'); + echo 'This content will be cached.'; + }); + +Keep in mind that calling either `lastModified` or `etag` will both set and check the cache value. +If the cache value is the same between requests, Flight will immediately send an HTTP 304 response and stop +processing. \ No newline at end of file