No Code Attached Yet
avatar AlexVinesmoke
AlexVinesmoke
24 Jan 2023

ETag header does not chandes if pagecache changed. Idea is make ETag as md5 of filecache time modified at pagecontroller.php.

protected function lastModified($id, $group)
{
$app = Factory::getApplication();
$filename = 'administrator/cache/' . $group. '/' .md5($app->get('secret')) . '-cache-' . $group . '-' . md5(md5(JPATH_CONFIGURATION) . '-' . $id . '-' . $app->getLanguage()->get('tag')). '.php';
if (file_exists($filename)) {
date_default_timezone_set('your server timezone...');
return date("F d Y H:i:s", filemtime($filename));
} else {
return 'file_not_exists';
}
}

public function get($id = false, $group = 'page')
{
    // If an id is not given, generate it from the request
    if (!$id)
    {
        $id = $this->_makeId();
    }
    $lastModified = md5($this->lastModified($id, $group));
    //$lastModifiedGzip = $lastModified.'-gzip';
    //var_dump($lastModifiedGzip);
    // If the etag matches the page id ... set a no change header and exit : utilize browser cache
    if (!headers_sent() && isset($_SERVER['HTTP_IF_NONE_MATCH']))
    {
        $etag = stripslashes($_SERVER['HTTP_IF_NONE_MATCH']);
        $etag = str_replace('"', '', $etag);
        //var_dump($etag);

        if ($etag == $lastModified)
        {
            $browserCache = $this->options['browsercache'] ?? false;

            if ($browserCache)
            {
                $this->_noChange();
           }
        }
    }

    // We got a cache hit... set the etag header and echo the page data
    $data = $this->cache->get($id, $group);

    $this->_locktest = (object) array('locked' => null, 'locklooped' => null);

    if ($data === false)
    {
        $this->_locktest = $this->cache->lock($id, $group);

        // If locklooped is true try to get the cached data again; it could exist now.
        if ($this->_locktest->locked === true && $this->_locktest->locklooped === true)
        {
            $data = $this->cache->get($id, $group);
        }
    }

    if ($data !== false)
    {
        /*if ($this->_locktest->locked === true)
        {*/
            $this->cache->unlock($id, $group);
        /*}*/

        $data = unserialize(trim($data));
        $data = Cache::getWorkarounds($data);

        $this->_setEtag($lastModified);

        return $data;
    }

    // Set ID and group placeholders
    $this->_id    = $id;
    $this->_group = $group;

    return false;
}
avatar AlexVinesmoke AlexVinesmoke - open - 24 Jan 2023
avatar joomla-cms-bot joomla-cms-bot - change - 24 Jan 2023
Labels Added: No Code Attached Yet
avatar joomla-cms-bot joomla-cms-bot - labeled - 24 Jan 2023
avatar AlexVinesmoke AlexVinesmoke - change - 24 Jan 2023
The description was changed
avatar AlexVinesmoke AlexVinesmoke - edited - 24 Jan 2023
avatar Quy Quy - change - 16 Feb 2023
Status New Closed
Closed_Date 0000-00-00 00:00:00 2023-02-16 16:11:33
Closed_By Quy
avatar Quy
Quy - comment - 16 Feb 2023

Closing as duplicate of #17192 which has more context for the issue.

avatar Quy Quy - close - 16 Feb 2023

Add a Comment

Login with GitHub to post a comment