RuntimeCache.php code cleanup
This commit is contained in:
parent
f08ecb7947
commit
9cef8e4394
1 changed files with 18 additions and 5 deletions
|
@ -1,7 +1,10 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
/** @noinspection PhpMissingFieldTypeInspection */
|
||||||
|
|
||||||
namespace ncc\Utilities;
|
namespace ncc\Utilities;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
use ncc\ThirdParty\Symfony\Filesystem\Filesystem;
|
use ncc\ThirdParty\Symfony\Filesystem\Filesystem;
|
||||||
|
|
||||||
class RuntimeCache
|
class RuntimeCache
|
||||||
|
@ -27,7 +30,7 @@
|
||||||
* @param $value
|
* @param $value
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public static function set($key, $value)
|
public static function set($key, $value): mixed
|
||||||
{
|
{
|
||||||
self::$cache[$key] = $value;
|
self::$cache[$key] = $value;
|
||||||
return $value;
|
return $value;
|
||||||
|
@ -39,7 +42,7 @@
|
||||||
* @param $key
|
* @param $key
|
||||||
* @return mixed|null
|
* @return mixed|null
|
||||||
*/
|
*/
|
||||||
public static function get($key)
|
public static function get($key): mixed
|
||||||
{
|
{
|
||||||
if(isset(self::$cache[$key]))
|
if(isset(self::$cache[$key]))
|
||||||
return self::$cache[$key];
|
return self::$cache[$key];
|
||||||
|
@ -53,7 +56,7 @@
|
||||||
* @param string $path
|
* @param string $path
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public static function setFileAsTemporary(string $path)
|
public static function setFileAsTemporary(string $path): void
|
||||||
{
|
{
|
||||||
if(!in_array($path, self::$temporary_files))
|
if(!in_array($path, self::$temporary_files))
|
||||||
self::$temporary_files[] = $path;
|
self::$temporary_files[] = $path;
|
||||||
|
@ -64,14 +67,17 @@
|
||||||
*
|
*
|
||||||
* @param string $path
|
* @param string $path
|
||||||
* @return void
|
* @return void
|
||||||
|
* @noinspection PhpUnused
|
||||||
*/
|
*/
|
||||||
public static function removeFileAsTemporary(string $path)
|
public static function removeFileAsTemporary(string $path): void
|
||||||
{
|
{
|
||||||
if(in_array($path, self::$temporary_files))
|
if(in_array($path, self::$temporary_files))
|
||||||
unset(self::$temporary_files[array_search($path, self::$temporary_files)]);
|
unset(self::$temporary_files[array_search($path, self::$temporary_files)]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @param bool $clear_memory
|
||||||
|
* @param bool $clear_files
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public static function clearCache(bool $clear_memory=true, bool $clear_files=true): void
|
public static function clearCache(bool $clear_memory=true, bool $clear_files=true): void
|
||||||
|
@ -86,9 +92,16 @@
|
||||||
$filesystem = new Filesystem();
|
$filesystem = new Filesystem();
|
||||||
foreach(self::$temporary_files as $file)
|
foreach(self::$temporary_files as $file)
|
||||||
{
|
{
|
||||||
if(file_exists($file))
|
try
|
||||||
|
{
|
||||||
$filesystem->remove($file);
|
$filesystem->remove($file);
|
||||||
}
|
}
|
||||||
|
catch (Exception $e)
|
||||||
|
{
|
||||||
|
// Ignore
|
||||||
|
unset($e);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Add table
Reference in a new issue