diff options
author | Benjamin Brahmer <info@b-brahmer.de> | 2023-08-22 18:26:42 +0200 |
---|---|---|
committer | Benjamin Brahmer <info@b-brahmer.de> | 2023-08-26 10:52:58 +0200 |
commit | da83f9a9b3cc2fe1216896f9da69caf8d13dec7c (patch) | |
tree | 07a4f3c7b671c5a7917f417d31412d97209d41a3 /lib/Utility/Cache.php | |
parent | b99320dd4aa9c5c732d331bd54d65e8010c4662d (diff) |
use unique name for cache folder
Signed-off-by: Benjamin Brahmer <info@b-brahmer.de>
Diffstat (limited to 'lib/Utility/Cache.php')
-rw-r--r-- | lib/Utility/Cache.php | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/lib/Utility/Cache.php b/lib/Utility/Cache.php new file mode 100644 index 000000000..6337487cf --- /dev/null +++ b/lib/Utility/Cache.php @@ -0,0 +1,59 @@ +<?php +/** + * Nextcloud - News + * + * This file is licensed under the Affero General Public License version 3 or + * later. See the COPYING file. + * + * @author Benjamin Brahmer <info@b-brahmer.de> + * @copyright 2023 Benjamin Brahmer + */ +namespace OCA\News\Utility; + +use OCP\ITempManager; +use OCP\IConfig; + +class Cache +{ + + + /** + * @var ITempManager + */ + private $ITempManager; + + /** + * @var IConfig + */ + private $IConfig; + + + public function __construct( + ITempManager $ITempManager, + IConfig $IConfig + ) { + $this->ITempManager = $ITempManager; + $this->IConfig = $IConfig; + } + + /** + * Get a news app cache directory + * + * @param String $name for the sub-directory, is created if not existing + * + * @return String $directory The path for the cache + */ + public function getCache(String $name): String + { + $baseDir = $this->ITempManager->getTempBaseDir(); + $instanceID = $this->IConfig->getSystemValue('instanceid'); + + $directory = join(DIRECTORY_SEPARATOR, [$baseDir, "news-" . $instanceID, 'cache', $name]); + + if (!is_dir($directory)) { + mkdir($directory, 0770, true); + } + + return $directory; + } +} |