Skip to content

Commit

Permalink
#645 - Rename getCanonical() to getCacheUrl()
Browse files Browse the repository at this point in the history
  • Loading branch information
johanjanssens committed Apr 12, 2021
1 parent d0fe8bd commit e5579af
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 19 deletions.
23 changes: 6 additions & 17 deletions code/site/components/com_pages/dispatcher/behavior/cacheable.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ protected function _actionValidate(KDispatcherContextInterface $context)
$response->setDate(new DateTime('now'));
$response->headers->set('Age', null);
$response->headers->set('Cache-Status', self::CACHE_REVALIDATED, false);
$response->headers->set('Content-Location', (string) $this->getContentLocation());
//$response->headers->set('Content-Location', (string) $this->getContentLocation());
}
else $response->headers->set('Age', max(time() - $response->getDate()->format('U'), 0));

Expand Down Expand Up @@ -190,8 +190,8 @@ protected function _actionCache(KDispatcherContextInterface $context)
}

$data = array(
'id' => $this->getContentLocation()->toString(KHttpUrl::PATH + KHttpUrl::QUERY),
'url' => rtrim((string) $this->getContentLocation(), '/'),
'id' => $this->getCacheUrl()->toString(KHttpUrl::PATH + KHttpUrl::QUERY),
'url' => rtrim((string) $this->getCacheUrl(), '/'),
'validators' => $this->getCacheValidators(),
'status' => !$response->isNotModified() ? $response->getStatusCode() : '200',
'token' => $this->getCacheToken(),
Expand Down Expand Up @@ -341,19 +341,8 @@ public function getCacheToken()
return $token;
}

public function getContentLocation()
public function getCacheUrl()
{
/**
* Get content location
*
* If Content-Location is included in a 2xx (Successful) response message and its value refers (after
* conversion to absolute form) to a URI that is the same as the effective request URI, then the recipient
* MAY consider the payload to be a current representation of that resource at the time indicated by the
* message origination date. For a GET (Section 4.3.1) or HEAD (Section 4.3.2) request, this is the same
* as the default semantics when no Content-Location is provided by the server.
*
* See: https://tools.ietf.org/html/rfc7231#section-3.1.4.2
*/
if(!$location = $this->getResponse()->headers->get('Content-Location'))
{
$location = $this->getRequest()->getUrl()
Expand All @@ -366,7 +355,7 @@ public function getContentLocation()

public function locateCache($url = null)
{
$key = $url ?? $this->getContentLocation()->toString(KHttpUrl::PATH + KHttpUrl::QUERY);
$key = $url ?? $this->getCacheUrl()->toString(KHttpUrl::PATH + KHttpUrl::QUERY);
$file = $this->getConfig()->cache_path . '/response_' . crc32($key) . '.php';

return $file;
Expand Down Expand Up @@ -465,7 +454,7 @@ public function storeCache($data)
{
if($this->getConfig()->cache)
{
$url = (string) $this->getContentLocation();
$url = (string) $this->getCacheUrl();
$path = $this->getConfig()->cache_path;

if(!is_dir($path) && (false === @mkdir($path, 0777, true) && !is_dir($path))) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function onAfterDispatcherCache(KEventInterface $event)
$response = $dispatcher->getResponse();

//Only cache static pages without a query string
if($event->result && !$dispatcher->getContentLocation()->getQuery() && $this->getConfig()->cache_path)
if($event->result && !$dispatcher->getCacheUrl()->getQuery() && $this->getConfig()->cache_path)
{
$file = $this->getFilePath($dispatcher);
$dir = dirname($file);
Expand Down Expand Up @@ -89,7 +89,7 @@ public function getCachePath()

public function getFilePath(ComPagesDispatcherHttp $dispatcher)
{
$path = $dispatcher->getContentLocation()->getPath(true);
$path = $dispatcher->getCacheUrl()->getPath(true);
$filename = array_pop($path);
$format = pathinfo($filename, PATHINFO_EXTENSION);

Expand Down

0 comments on commit e5579af

Please sign in to comment.