wiki/HowtoCacheHTTP.md

48 lines
1 KiB
Markdown
Raw Permalink Normal View History

2021-06-21 10:04:27 +02:00
---
categories: web http
title: Howto Cache HTTP
...
2016-12-29 11:25:39 +01:00
**Cette page a été importée automatiquement de notre ancien wiki mais n'a pas encore été révisée.**
2021-06-21 10:04:27 +02:00
## Documentation
2016-12-29 11:25:39 +01:00
2021-06-21 10:03:00 +02:00
* <http://fr.wikipedia.org/wiki/Cache-Control>
* <https://developer.mozilla.org/fr/docs/Web/HTTP/Caching>
* <https://web.dev/http-cache/>
2016-12-29 11:25:39 +01:00
2021-06-21 10:04:27 +02:00
## Exemples
En-têtes relatifs au cache HTTP :
2016-12-29 11:25:39 +01:00
~~~
Cache-Control:
Max-Age:
Age:
Pragma:
Expires:
Last-Modified:
~~~
Exemple de mise en cache en PHP :
2021-06-21 10:05:14 +02:00
~~~{.php}
2016-12-29 11:25:39 +01:00
$offset=3600*20; //Forte période 20h
//$offset=3600*3; //Période normale 3h
header("Cache-Control: public, max-age=$offset");
header("Expires: " .gmdate("D, d M Y H:i:s",time()+$offset). " GMT");
header("Last-Modified: " .gmdate("D, d M Y H:i:s",time()). " GMT");
header("X-generated-at: " .date(DATE_RFC822));
~~~
Exemple de non-mise en cache en PHP :
2021-06-21 10:05:14 +02:00
~~~{.php}
2016-12-29 11:25:39 +01:00
header("Pragma: no-cache");
header("Cache-Control: no-cache");
~~~
2021-06-21 10:03:00 +02:00
## Tester le comportement du cache
Cet outil en ligne permet d'interpéter les en-têtes HTTP renvoyées pour une URL : <https://redbot.org/>