@ OP:
Ниже приведен некоторый закомментированный код для достижения того, что вы просили.
@ Клетус:
Вы сказали, что memcached - это то, чего хочет OP, и что это не то, для чего предназначен Squid.
Я не знаю, для чего был разработан Squid, но я знаю, для чего он используется , и определенно есть люди, использующие его в качестве обратного прокси-сервера для снятия нагрузки с динамической генерации страниц. Никакой «врезки» не требуется, кроме стандартных заголовков HTTP.
Я не уверен, почему вы так быстро порекомендовали memcached, не зная больше о природе приложения и среде.
<?php
// the time we got hit and generated content
$now = time();
$generatedAt = gmdate('D, d M Y H:i:s T', $now);
// the last modified date (midnight on the same day of generation, as
// per your business-rule)
$lastModified = gmdate('D, d M Y 00:00:00 T', $now);
// date of expiry (24 hours after the last modified date, as per your
// business-rule)
$expiresAt = gmdate('D, d M Y H:i:s T', strtotime($lastModified) + 86400);
// the minimum required http headers to make Squid do what you asked is
// Last-modified and Cache-control. We need to give Cache-control the
// expiry time in terms of "age" (in seconds) so we calculate that below.
// Optionally you could also provide the "Expires: $expiresAt" header to
// tell the browser/client the same information, just in a different way.
// This is not required for Squid though.
$maxAge = strtotime($expiresAt) - strtotime($generatedAt);
header('Last-modified: ' . $lastModified);
header('Cache-control: max-age=' . $maxAge);
// The rest is simply informational
header('Content-type: text/plain');
echo "The content of this page was last modified at $lastModified\n";
echo "This page was generated at $generatedAt and will be cached by Squid for $maxAge seconds until $expiresAt\n";
// Sample output:
//
// The content of this page was last modified at Tue, 13 Jan 2009 00:00:00 GMT
// This page was generated at Tue, 13 Jan 2009 04:29:33 GMT and will be cached by Squid for 70227 seconds until Wed, 14 Jan 2009 00:00:00 GMT