summaryrefslogtreecommitdiff
path: root/app/Core/FileCache.php
diff options
context:
space:
mode:
authorFrédéric Guillot <fred@kanboard.net>2015-01-02 17:19:13 -0500
committerFrédéric Guillot <fred@kanboard.net>2015-01-02 17:19:13 -0500
commit3076ba22dd8346725b4e1ad757532c00df5b18d9 (patch)
treee893c113c34d86c5dc923953754dc68c4b1d842d /app/Core/FileCache.php
parentc32567857db9bb1a6dfa339f58d817c97f64db11 (diff)
Fix bugs, improve perfs and use SimpleLogger instead of Monolog
Diffstat (limited to 'app/Core/FileCache.php')
-rw-r--r--app/Core/FileCache.php41
1 files changed, 41 insertions, 0 deletions
diff --git a/app/Core/FileCache.php b/app/Core/FileCache.php
new file mode 100644
index 00000000..2037f271
--- /dev/null
+++ b/app/Core/FileCache.php
@@ -0,0 +1,41 @@
+<?php
+
+namespace Core;
+
+class FileCache extends Cache
+{
+ const CACHE_FOLDER = 'data/cache/';
+
+ public function init()
+ {
+ if (! is_dir(self::CACHE_FOLDER)) {
+ mkdir(self::CACHE_FOLDER);
+ }
+ }
+
+ public function set($key, $value)
+ {
+ file_put_contents(self::CACHE_FOLDER.$key, json_encode($value));
+ }
+
+ public function get($key)
+ {
+ if (file_exists(self::CACHE_FOLDER.$key)) {
+ return json_decode(file_get_contents(self::CACHE_FOLDER.$key), true);
+ }
+
+ return null;
+ }
+
+ public function flush()
+ {
+ foreach (glob(self::CACHE_FOLDER.'*') as $filename) {
+ @unlink($filename);
+ }
+ }
+
+ public function remove($key)
+ {
+ @unlink(self::CACHE_FOLDER.$key);
+ }
+}