<commit_before><?php

namespace Concrete\Core\Cache\Page;
use Config;
use \Page as ConcretePage;
use Loader;

class FilePageCache extends PageCache {

	public function getRecord($mixed) {
		$file = $this->getCacheFile($mixed);
		if (file_exists($file)) {
			$contents = file_get_contents($file);
			$record = @unserialize($contents);
			if ($record instanceof PageCacheRecord) {
				return $record;
			}
		}
	}

	protected function getCacheFile($mixed) {
       	$key = $this->getCacheKey($mixed);
       	$filename = $key . '.cache';
		if ($key) {
			if (strlen($key) == 1) {
				$dir = Config::get('concrete.cache.page.directory') . '/' . $key;
			} else if (strlen($key) == 2) {
				$dir = Config::get('concrete.cache.page.directory') . '/' . $key[0] . '/' . $key[1];
			} else {
				$dir = Config::get('concrete.cache.page.directory') . '/' . $key[0] . '/' . $key[1] . '/' . $key[2];
			}
			if ($dir && (!is_dir($dir))) {
				@mkdir($dir, DIRECTORY_PERMISSIONS_MODE, true);
			}
			$path = $dir . '/' . $filename;
			return $path;
		}
	}

	public function purgeByRecord(\Concrete\Core\Cache\Page\PageCacheRecord $rec) {
		$file = $this->getCacheFile($rec);
		if ($file && file_exists($file)) {
			@unlink($file);
		}
	}

	public function flush() {
		$fh = Loader::helper('file');
		$fh->removeAll(Config::get('concrete.cache.page.directory'));
	}

	public function purge(ConcretePage $c) {
		$file = $this->getCacheFile($c);
		if ($file && file_exists($file)) {
			@unlink($file);
		}<commit_msg>Get hashed cache file name with sha-256<commit_after><?php

namespace Concrete\Core\Cache\Page;
use Config;
use \Page as ConcretePage;
use Loader;

class FilePageCache extends PageCache {

	public function getRecord($mixed) {
		$file = $this->getCacheFile($mixed);
		if (file_exists($file)) {
			$contents = file_get_contents($file);
			$record = @unserialize($contents);
			if ($record instanceof PageCacheRecord) {
				return $record;
			}
		}
	}

	protected function getCacheFile($mixed) {
		$key = $this->getCacheKey($mixed);
		if ($key) {
			$key = hash('sha256',$key);
			$filename = $key . '.cache';
			$dir = Config::get('concrete.cache.page.directory') . '/' . $key[0] . '/' . $key[1] . '/' . $key[2];
			if ($dir && (!is_dir($dir))) {
				@mkdir($dir, DIRECTORY_PERMISSIONS_MODE, true);
			}
			$path = $dir . '/' . $filename;
			return $path;
		}
	}

	public function purgeByRecord(\Concrete\Core\Cache\Page\PageCacheRecord $rec) {
		$file = $this->getCacheFile($rec);
		if ($file && file_exists($file)) {
			@unlink($file);
		}
	}

	public function flush() {
		$fh = Loader::helper('file');
		$fh->removeAll(Config::get('concrete.cache.page.directory'));
	}

	public function purge(ConcretePage $c) {
		$file = $this->getCacheFile($c);
		if ($file && file_exists($file)) {
			@unlink($file);
		}
{'fraction_non_alphanumeric': 0.198005698005698, 'fraction_numerical': 0.005698005698005698, 'mean_word_length': 3.6738768718801995, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4769632', 'n_tokens_mistral': 1144, 'n_tokens_neox': 1006, 'n_words': 191}