1
0
mirror of https://git.tt-rss.org/git/tt-rss.git synced 2025-12-13 07:45:55 +00:00

add classes/diskcache

This commit is contained in:
Andrew Dolgov
2019-08-13 12:04:36 +03:00
parent b68db2d02c
commit 86308b30ea

51
classes/diskcache.php Normal file
View File

@@ -0,0 +1,51 @@
<?php
class DiskCache {
private $dir;
public function __construct($dir) {
$this->dir = basename($dir);
}
public function getDir() {
return $this->dir;
}
public function exists($filename) {
return file_exists($this->getFullPath($filename));
}
public function getSize($filename) {
if ($this->exists($filename))
return filesize($this->getFullPath($filename));
else
return -1;
}
public function getFullPath($filename) {
$filename = basename($filename);
return CACHE_DIR . "/" . $this->dir . "/" . $filename;
}
public function put($filename, $data) {
return file_put_contents($this->getFullPath($filename), $data);
}
public function touch($filename) {
return touch($this->getFullPath($filename));
}
public function get($filename) {
if ($this->exists($filename))
return file_get_contents($this->getFullPath($filename));
else
return null;
}
public function getMimeType($filename) {
if ($this->exists($filename))
return mime_content_type($this->getFullPath($filename));
else
return null;
}
}