PHP 8.4+ Framework
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
CodeHydrater/src/classes/php_file_cache.php

39 lines
864 B

<?php
declare(strict_types=1);
namespace CodeHydrater;
/**
* @author Robert Strutts <Bob_586@Yahoo.com>
* @copyright (c) 2025, Robert Strutts
* @license MIT
*/
/**
* May be used by the Liquid Template Engine
*/
class php_file_cache {
protected $cache_path;
public function __construct($path) {
$this->cache_path = rtrim($path, '/') . '/';
if (!is_dir($this->cache_path)) {
mkdir($this->cache_path, 0775, true);
}
}
public function get($key) {
$file = $this->cache_path . md5($key) . '.cache.php';
if (file_exists($file)) {
return unserialize(file_get_contents($file));
}
return null;
}
public function set($key, $value) {
$file = $this->cache_path . md5($key) . '.cache.php';
file_put_contents($file, serialize($value));
}
}