php önbelleğe alma sorunu

0 Cevap php

Ben bazı görüntülerin önbelleğe alma için bir sınıf var

<?php
class Vp_CacheImage
{
    public function cache($cacheTime, $place) // $place = id of image (between 1 and 100)
    {
        $send_body = true; 
        $etag = '"' . md5(date('d.m.Y', time()) . $place) . '"';
        header("ETag: " . $etag );
        header("Last-modified: " . gmdate("D, d M Y H:i:s", $cacheTime) . " GMT");

        $inm = explode(',', getenv("HTTP_IF_NONE_MATCH"));
        foreach ($inm as $i)
        {
            if (trim($i) == $etag || trim($i) == $cacheTime)
            {
                header ("HTTP/1.0 304 Not Modified");
                $send_body = false;
            }
        }

        if(getenv("HTTP_IF_MODIFIED_SINCE") == gmdate("D, d M Y H:i:s", $cacheTime). " GMT")
        {
            header ("HTTP/1.0 304 Not Modified");
            $send_body = false;
        }

        header("Expires: " . gmdate("D, d M Y H:i:s", time() + Config::$config['cache']['images']['topvideo']) . " GMT");
        header("Cache-Control: max-age=" . Config::$config['cache']['images']['topvideo'] . ", must-revalidate");
        if ($send_body) return true; else return false;
    }
}

Bu çalışıyor. Ama bir resim, bazen yeniden, ve önbellek alınan değil yapmak zorunda. Nasıl yapılacak?

0 Cevap