<commit_before><?php
/**
 * A simple file-based cache.
 *
 * @internal Data is base64 encoded to avoid unserialization issues ('unserialize(): Error at offset') which
 * could be caused by:
 * - inconsistent line endings
 * - unescaped quotes/slashes etc
 * - miscounted unicode characters
 *
 * @see https://github.com/YahnisElsts/wp-update-server/pull/11
 */
class Wpup_FileCache implements Wpup_Cache {
	protected $cacheDirectory;

	public function __construct($cacheDirectory) {
		$this->cacheDirectory = $cacheDirectory;
	}

	/**
	 * Get cached value.
	 *
	 * @param string $key
	 * @return mixed|null
	 */
	public function get($key) {
		$filename = $this->getCacheFilename($key);
		if ( is_file($filename) && is_readable($filename) ) {
			$cache = unserialize(base64_decode(file_get_contents($filename)));
			if ( $cache['expiration_time'] < time() ) {
				return null; //Cache expired.<commit_msg>Delete a cache file if it's expired<commit_after><?php
/**
 * A simple file-based cache.
 *
 * @internal Data is base64 encoded to avoid unserialization issues ('unserialize(): Error at offset') which
 * could be caused by:
 * - inconsistent line endings
 * - unescaped quotes/slashes etc
 * - miscounted unicode characters
 *
 * @see https://github.com/YahnisElsts/wp-update-server/pull/11
 */
class Wpup_FileCache implements Wpup_Cache {
	protected $cacheDirectory;

	public function __construct($cacheDirectory) {
		$this->cacheDirectory = $cacheDirectory;
	}

	/**
	 * Get cached value.
	 *
	 * @param string $key
	 * @return mixed|null
	 */
	public function get($key) {
		$filename = $this->getCacheFilename($key);
		if ( is_file($filename) && is_readable($filename) ) {
			$cache = unserialize(base64_decode(file_get_contents($filename)));
			if ( $cache['expiration_time'] < time() ) {
				$this->clear($key);
				return null; //Cache expired.
{'fraction_non_alphanumeric': 0.13592233009708737, 'fraction_numerical': 0.006472491909385114, 'mean_word_length': 4.196078431372549, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 8, 'https://': 2, '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': '7630158', 'n_tokens_mistral': 615, 'n_tokens_neox': 559, 'n_words': 146}