| <?php |
|
|
| namespace Kanboard\Core\Cache; |
|
|
| use Kanboard\Core\Tool; |
| use LogicException; |
|
|
| |
| |
| |
| |
| |
| class FileCache extends BaseCache |
| { |
| |
| |
| |
| |
| |
| |
| |
| public function set($key, $value) |
| { |
| $this->createCacheFolder(); |
| file_put_contents($this->getFilenameFromKey($key), serialize($value)); |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| public function get($key) |
| { |
| $filename = $this->getFilenameFromKey($key); |
|
|
| if (file_exists($filename)) { |
| return unserialize(file_get_contents($filename)); |
| } |
|
|
| return null; |
| } |
|
|
| |
| |
| |
| |
| |
| public function flush() |
| { |
| $this->createCacheFolder(); |
| Tool::removeAllFiles(CACHE_DIR, false); |
| } |
|
|
| |
| |
| |
| |
| |
| |
| public function remove($key) |
| { |
| $filename = $this->getFilenameFromKey($key); |
|
|
| if (file_exists($filename)) { |
| unlink($filename); |
| } |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| protected function getFilenameFromKey($key) |
| { |
| return CACHE_DIR.DIRECTORY_SEPARATOR.$key; |
| } |
|
|
| |
| |
| |
| |
| |
| |
| protected function createCacheFolder() |
| { |
| if (! is_dir(CACHE_DIR)) { |
| if (! mkdir(CACHE_DIR, 0755)) { |
| throw new LogicException('Unable to create cache directory: '.CACHE_DIR); |
| } |
| } |
| } |
| } |
|
|