Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 21 additions & 8 deletions services/Htmlcache_HtmlcacheService.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function checkForCacheFile()
ob_start();
}
}

public function canCreateCacheFile()
{
// Skip if we're running in devMode
Expand All @@ -58,18 +58,31 @@ public function canCreateCacheFile()
if (craft()->request->isLivePreview()) {
return false;
}

// Skip if it's a post/ajax request
if (!craft()->request->isGetRequest()) {
return false;
}

return true;
}


public function header_sent($header) {
$headers = headers_list();
$header = trim($header,': ');
$result = false;

foreach ($headers as $hdr) {
if (strpos($hdr, $header) !== false) {
$result = true;
}
}
return $result;
}

public function createCacheFile()
{
if ($this->canCreateCacheFile() && http_response_code() == 200) {
if ($this->canCreateCacheFile() && !$this->header_sent("No-Cache") && http_response_code() == 200) {
$content = ob_get_contents();
ob_end_flush();
$file = $this->getCacheFileName();
Expand All @@ -83,7 +96,7 @@ public function createCacheFile()
}
}
}

public function clearCacheFiles()
{
// @todo split between all/single cache file
Expand All @@ -92,17 +105,17 @@ public function clearCacheFiles()
}
return true;
}

private function getCacheFileName($withDirectory = true)
{
return \htmlcache_filename($withDirectory);
}

private function getCacheFileDirectory()
{
return \htmlcache_directory();
}

public function log($settings, $errors, $level)
{
// Firstly, store in plugin log file (use $level to control log level)
Expand Down