1
0
mirror of https://github.com/chylex/Nextcloud-News.git synced 2024-12-22 14:42:47 +01:00
Nextcloud-News/lib/Utility/Cache.php
Benjamin Brahmer da83f9a9b3 use unique name for cache folder
Signed-off-by: Benjamin Brahmer <info@b-brahmer.de>
2023-08-26 10:52:58 +02:00

60 lines
1.2 KiB
PHP

<?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;
}
}