From 86308b30eadf1e42a2007b13327c12748f222018 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Tue, 13 Aug 2019 12:04:36 +0300 Subject: [PATCH] add classes/diskcache --- classes/diskcache.php | 51 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 classes/diskcache.php diff --git a/classes/diskcache.php b/classes/diskcache.php new file mode 100644 index 000000000..fdfc46cb1 --- /dev/null +++ b/classes/diskcache.php @@ -0,0 +1,51 @@ +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; + } +}