ramzes, делал как то кэш файлов и отчистку по времени
не ttl, на основе времени создания файла и как раз хеши применял
пример (+/-)
class Kcache extends KimageUtils {
private $file;
public $uploadDir = 'upload';
public $test = '';
public function __construct($source, $x, $y) {
$image = imagecreatetruecolor($x, $y);
$this->transparent($image);
imagecopyresampled($image, $source, 0, 0, 0, 0, $x, $y, $x, $y);
$tmpfile = tempnam($this->uploadDir . '/tmp', 'bb_');
imagepng($image, $tmpfile, 9, PNG_ALL_FILTERS);
$md5 = md5_file($tmpfile);
if (!file_exists($this->uploadDir . '/' . $md5 . '.png')) {
file_put_contents($this->uploadDir . '/' . $md5 . '.png', file_get_contents($tmpfile));
} // тут обработка дубля
unlink($tmpfile);
$this->file = $this->uploadDir . '/' . $md5 . '.png';
}
public function getFile() {
return $this->file;
}
public function base64() {
return $this->output_base64(file_get_contents($this->getFile()));
}
public function clearCache($per) {
$periods = array(
'i' => 60,
'h' => 3600, // i*60
'd' => 86400, // h*24
'w' => 604800, // d*7
'm' => 2419200, // w*30
'y' => 29030400, // m*12
);
$per = strtolower($per);
$int = abs(intval($per[0]));
$int = $int > 0 ? $int : 1;
$lit = array_key_exists($per[1], $periods) ? $per[1] : 'y';
$period = time() - ($int * $periods[$lit]);
foreach(new DirectoryIterator($this->uploadDir . '/') as $fileInfo) { // TODO: GlobItertor
if (preg_match('/^(.*.png)$/i', $fileInfo->getFilename()) && ($fileInfo->getMTime() < $period)) {
unlink($this->uploadDir . '/' . $fileInfo->getFilename());
}
}
}
}ну и юзать
#$cache->clearCache('1i'); // 2y , 3m, 5h ....