From b0bee473ff11118f485aa11d7455e86c9880f4af Mon Sep 17 00:00:00 2001 From: qkqpttgf <45693631+qkqpttgf@users.noreply.github.com> Date: Mon, 17 Aug 2020 16:26:22 +0800 Subject: [PATCH] little change in cache --- common.php | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/common.php b/common.php index 7e67af8..e6204c4 100644 --- a/common.php +++ b/common.php @@ -540,14 +540,28 @@ function isHideFile($name) function getcache($str) { - $cache = new \Doctrine\Common\Cache\FilesystemCache(sys_get_temp_dir(), __DIR__.'/Onedrive/'.$_SERVER['disktag']); + $cache = filecache(); return $cache->fetch($str); } function savecache($key, $value, $exp = 1800) { - $cache = new \Doctrine\Common\Cache\FilesystemCache(sys_get_temp_dir(), __DIR__.'/Onedrive/'.$_SERVER['disktag']); - $cache->save($key, $value, $exp); + $cache = filecache(); + return $cache->save($key, $value, $exp); +} + +function filecache() +{ + $dir = sys_get_temp_dir(); + if (!is_writable($dir)) { + if ( is_writable(__DIR__ . '/tmp/') ) $dir = __DIR__ . '/tmp/'; + if ( mkdir(__DIR__ . '/tmp/', 0777) ) $dir = __DIR__ . '/tmp/'; + } + $tag = __DIR__ . '/OneManager/' . $_SERVER['disktag']; + while (strpos($tag, '/')>-1) $tag = str_replace('/', '_', $tag); + // error_log('DIR:' . $dir . ' TAG: ' . $tag); + $cache = new \Doctrine\Common\Cache\FilesystemCache($dir, $tag); + return $cache; } function getconstStr($str)