====== Caching ====== Hier werden nur Caching Headers im Response von GET Request behandelt. ===== Einträge dem Cache hinzufügen (Cacheability) ===== Dieses Kapitel behandelt die //Cache-Control// direktiven * public * private * no-store * (max-age) * (s-maxage) Algorithmus zur Bestimmung der Cachebarkeit [([[https://www.greenbytes.de/tech/webdav/rfc7234.html#response.cacheability]])] if( Methode speicherbar und unterstützt vom cache && Statuscode unterstützt vom cache && Statuscode != 1xx && !request.no-store && !response.no-store && (shared => !response.private) && ( (shared => !request.Authorization) || unless the response explicitly allows it (see Section 3.2) ) && ( response.Expires || response.max-age || (shared && response.s-maxage) || (response.Cache-Control Extension (see Section 5.2.3) that allows it to be cached) || (response.status.cacheable_by_default) || (response.public) ) ) { Vermutlich Speichern } else { Definitiv nicht speichern } Speicherbare Methoden sind [([[https://www.greenbytes.de/tech/webdav/rfc7231.html#cacheable.methods]])]: * GET [([[https://www.greenbytes.de/tech/webdav/rfc7231.html#rfc.section.4.3.1.p.5]])] * HEAD [([[https://www.greenbytes.de/tech/webdav/rfc7231.html#rfc.section.4.3.2.p.3]])] * POST mit explicit freshness information (s. [[https://www.greenbytes.de/tech/webdav/rfc7234.html#calculating.freshness.lifetime|Calculating Freshness Lifetime]]) [([[https://www.greenbytes.de/tech/webdav/rfc7231.html#rfc.section.4.3.3.p.4]])]. Dazu gibts eine [[https://www.mnot.net/blog/2012/09/24/caching_POST|weitere Erklärung]] und ein [[https://www.ebayinc.com/stories/blogs/tech/caching-http-post-requests-and-responses/|Beispiel]] von eBay. Zu den Statuscodes die standardmäßig cachebar sind gehören unter anderem: 200, 203, 204, 206, 300, 301, 308, 404, 405, 410, 414, und 501 [([[https://www.greenbytes.de/tech/webdav/rfc7231.html#rfc.section.6.1.p.2]])][([[https://www.greenbytes.de/tech/webdav/rfc7538.html#rfc.section.3.p.3]])] Die ''Statuscode != 1xx'' Einschränkung kommt aus dem [[https://greenbytes.de/tech/webdav/draft-ietf-httpbis-cache-03.html#rfc.section.3|aktuellen draft]] und sorgt dafür das nur finale (>= 200) Antworten gespeichert werden. ===== Einträge aus dem Cache löschen (Invalidation) ===== ===== Einträge aus dem Cache holen ===== Dieses Kapitel behandelt die //Cache-Control// direktiven * no-cache if( Anfrage.URI == Eintrag.URI && passtZusammen(Anfrage.Methode, Eintrag.Methode) && Alle Header des Eintrags passen zu denen der Anfrage && ( (Anfrage.Pragma.no-cache || Anfrage.Cache-Control.no-cache) => erfolgreiche validierung von Eintrag ) && ( Eintrag.Cache-Control.no-cache => erfolgreiche validierung von Eintrag ) && ( Eintrag.fresh || Eintrag.can_be_served_stale (see Section 4.2.4) || erfolgreiche validierung von Eintrag ) ) { Eintrag verwenden } else { Eintrag nicht verwenden } ==== passtZusammen(Anfrage_Methode, Eintrag_Methode) ==== * Ein GET Eintrag kann eine GET oder eine HEAD Anfrage beantworten [([[https://www.greenbytes.de/tech/webdav/rfc7231.html#rfc.section.4.3.1.p.5]])]. * Ein HEAD Eintrag kann eine HEAD Anfrage beantworten [([[https://www.greenbytes.de/tech/webdav/rfc7231.html#rfc.section.4.3.2.p.3]])]. * Ein POST Eintrag kann * eine GET Anfrage beantworten, wenn der Eintrag ''Content-Location'' gleich der Anfrage URI und den Status-Code 200 hat [([[https://www.greenbytes.de/tech/webdav/rfc7231.html#rfc.section.4.3.3.p.4]])]. * eine POST Anfrage mit dem selben Body?? | |^ Eintrag ||| | ::: | ::: ^ GET ^ HEAD ^ POST ^ ^ Anfrage ^ GET | (V) | (X) | (V), wenn der Eintrag Content-Location gleich der Anfrage URI und den Status-Code 200 hat [([[https://www.greenbytes.de/tech/webdav/rfc7231.html#rfc.section.4.3.3.p.4]])] | | ::: ^ HEAD | (V) | (V) | ?? | | ::: ^ POST | (X) | (X) | ( (V) )?? s. eBay Beispiel | ===== Weiteres ===== Dieser Abschnitt ist noch hochgradig Falsch! * public proxy (shared cache) vs private browser cache * Neu Laden vs validieren ^ ''Cache-Control'' vom Server ^ Für ^ Funktion ^ Typ ^ | ''%%no-cache%%'' | | Immer -> validieren | Cachability | | ''%%public%%'' | | Private (V) / Shared (V) | Cachability | | ''%%private%%'' | Shared | Private (V) / Shared (X) | Cachability | | ''%%max-age=%%'' | Private / Shared | Relative Cache Zeit | Expiration | | ''%%s-maxage=%%'' | Shared | Relative Cache Zeit (vorrang vor ''Expires'' und ''s-maxage'') | Expiration | | ''%%must-revalidate%%'' | Private / Shared | Abgelaufen -> validieren | Re{validate,loading} | | ''%%proxy-revalidate%%'' | Shared | Abgelaufen -> validieren | Re{validate,loading} | | ''%%immutable%%'' | | Nicht abgelaufen -> verwenden (auch bei F5, aber nicht bei Shift+F5) / Abgelaufen ->Nicht verwenden [(http://bitsup.blogspot.com/2016/05/cache-control-immutable.html)] | Re{validate,loading} | | ''%%no-store%%'' | | Cachability: Private (X) / Shared (X) | Other | | ''%%no-transform%%'' | | Gecachten content nicht verändern (z.B. Optimieren) | Other | * https://developer.mozilla.org/en-US/docs/Web/HTTP/Caching * [[https://developers.google.com/web/fundamentals/performance/optimizing-content-efficiency/http-caching|Entscheidungsbaum, welche ''Cache-Control'' direktiven verwendet werden sollen]] * https://www.slideshare.net/martinmartin7777/http-caching-basics-66553113 * https://www.keycdn.com/blog/http-cache-headers * https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control * https://www.fastly.com/blog/understanding-vary-header-browser * https://www.digitalocean.com/community/tutorials/web-caching-basics-terminology-http-headers-and-caching-strategies * [[https://redbot.org/|REDbot]]: Caching Header online analyse tool * Preload ggf. auch bei Edge caches * POST, PUT und DELETE invalidieren private und shared cached. [([[https://www.mnot.net/blog/2006/02/18/invalidation]])] * [[https://www.greenbytes.de/tech/webdav/rfc7234.html|RFC 7234]]: Hypertext Transfer Protocol (HTTP/1.1): Caching * [[https://www.greenbytes.de/tech/webdav/rfc7231.html|RFC 7231]]: Hypertext Transfer Protocol (HTTP/1.1): Semantics and Content * [[https://greenbytes.de/tech/webdav/draft-ietf-httpbis-cache-03.html|draft-ietf-httpbis-cache-03]]: HTTP Caching (obsoletes RFC 7234) * [[https://github.com/mnot/redbot/blob/master/redbot/message/cache.py#L17|REDbot's Algorithmus zur Cache Header Auswertung]]. * [[http://www.iana.org/assignments/http-cache-directives/http-cache-directives.xhtml|Liste an ''Cache-Control'' direktiven]] bei der IANA. * [[https://www.mnot.net/blog/2017/03/16/browser-caching|Zusammenfassung wie Browser Caching umsetzen]] (Kompatibilitäts-Testergbnisse) * [[https://github.com/kornelski/http-cache-semantics/blob/master/index.js|JavaScript implementierung eines Caches]].