Domyślnie Apache2 nie ma włączonego cache’owania. Odpowiadają za to 2 moduły: mod_expieres, mod_headers.
Sprawdzenie jakie moduły są załadowane
# apache2ctl -t -D DUMP_MODULES
mod_expires: Expires, Last-Modified mod_headers: Cache-Control, ETag
Automatyczne generowanie nagłówków przez serwer.
### aktywuj mod_expires ExpiresActive On ### Wygasaj .gif 1 miesiąc od momentu uzyskania dostępu ExpiresByType image / gif A2592000 ### Wszystkie pozostałe wygasają 1 dzień od ostatniej modyfikacji - (alternatywna składnia) ExpiresDefault „modyfication plus 1 day” ### Zastosuj nagłówek Cache-Control do pliku index.html <Files index.html> Header append Cache-Control „public, must-revalidate” </Files>
Użycie PHP
header("Cache-Control: must-revalidate"); $offset = 60 * 60 * 24 * 3; // wygasa za 3 dni // Datę należy podać w specjalnym formacie $ExpStr = "Expires: " . gmdate("D, d M Y H:i:s", time() + $offset) . " GMT"; header($ExpStr);
Expires: Thu, 29 Oct 1998 17:04:19 GMT