Restructure Cache to follow new paradigm

This commit is contained in:
Philipp 2021-10-23 10:49:27 +02:00
parent 6a85d09c59
commit 68046573a4
No known key found for this signature in database
GPG key ID: 24A7501396EB5432
52 changed files with 103 additions and 71 deletions

View file

@ -22,7 +22,7 @@
use Friendica\App;
use Friendica\Content\ForumManager;
use Friendica\Content\Text\BBCode;
use Friendica\Core\Cache\Duration;
use Friendica\Core\Cache\Enum\Duration;
use Friendica\Core\Hook;
use Friendica\Database\DBA;
use Friendica\DI;

View file

@ -26,7 +26,7 @@ use FastRoute\DataGenerator\GroupCountBased;
use FastRoute\Dispatcher;
use FastRoute\RouteCollector;
use FastRoute\RouteParser\Std;
use Friendica\Core\Cache\Duration;
use Friendica\Core\Cache\Enum\Duration;
use Friendica\Core\Cache\ICache;
use Friendica\Core\Hook;
use Friendica\Core\L10n;

View file

@ -23,7 +23,7 @@ namespace Friendica\Console;
use Asika\SimpleConsole\CommandArgsException;
use Friendica\App;
use Friendica\Core\Cache\Duration;
use Friendica\Core\Cache\Enum\Duration;
use Friendica\Core\Cache\ICache;
use RuntimeException;

View file

@ -26,7 +26,7 @@ use DOMNode;
use DOMText;
use DOMXPath;
use Exception;
use Friendica\Core\Cache\Duration;
use Friendica\Core\Cache\Enum\Duration;
use Friendica\Core\Hook;
use Friendica\Core\Renderer;
use Friendica\Database\Database;

View file

@ -22,7 +22,7 @@
namespace Friendica\Content;
use Friendica\Core\Addon;
use Friendica\Core\Cache\Duration;
use Friendica\Core\Cache\Enum\Duration;
use Friendica\Core\Protocol;
use Friendica\Core\Renderer;
use Friendica\Database\DBA;

View file

@ -19,7 +19,7 @@
*
*/
namespace Friendica\Core\Cache;
namespace Friendica\Core\Cache\Enum;
/**
* Enumeration for cache durations

View file

@ -19,7 +19,7 @@
*
*/
namespace Friendica\Core\Cache;
namespace Friendica\Core\Cache\Enum;
/**
* Enumeration for cache types

View file

@ -19,7 +19,7 @@
*
*/
namespace Friendica\Factory;
namespace Friendica\Core\Cache\Factory;
use Friendica\App\BaseURL;
use Friendica\Core\Cache;
@ -41,7 +41,7 @@ class CacheFactory
/**
* @var string The default cache if nothing set
*/
const DEFAULT_TYPE = Cache\Type::DATABASE;
const DEFAULT_TYPE = Cache\Enum\Type::DATABASE;
/**
* @var IConfig The IConfiguration to read parameters out of the config
@ -92,27 +92,27 @@ class CacheFactory
}
switch ($type) {
case Cache\Type::MEMCACHE:
$cache = new Cache\MemcacheCache($this->hostname, $this->config);
case Cache\Enum\Type::MEMCACHE:
$cache = new Cache\Type\MemcacheCache($this->hostname, $this->config);
break;
case Cache\Type::MEMCACHED:
$cache = new Cache\MemcachedCache($this->hostname, $this->config, $this->logger);
case Cache\Enum\Type::MEMCACHED:
$cache = new Cache\Type\MemcachedCache($this->hostname, $this->config, $this->logger);
break;
case Cache\Type::REDIS:
$cache = new Cache\RedisCache($this->hostname, $this->config);
case Cache\Enum\Type::REDIS:
$cache = new Cache\Type\RedisCache($this->hostname, $this->config);
break;
case Cache\Type::APCU:
$cache = new Cache\APCuCache($this->hostname);
case Cache\Enum\Type::APCU:
$cache = new Cache\Type\APCuCache($this->hostname);
break;
default:
$cache = new Cache\DatabaseCache($this->hostname, $this->dba);
$cache = new Cache\Type\DatabaseCache($this->hostname, $this->dba);
}
$profiling = $this->config->get('system', 'profiling', false);
// In case profiling is enabled, wrap the ProfilerCache around the current cache
if (isset($profiling) && $profiling !== false) {
return new Cache\ProfilerCache($cache, $this->profiler);
return new Cache\Type\ProfilerCache($cache, $this->profiler);
} else {
return $cache;
}

View file

@ -21,6 +21,8 @@
namespace Friendica\Core\Cache;
use Friendica\Core\Cache\Enum\Duration;
/**
* Cache Interface
*/

View file

@ -21,6 +21,8 @@
namespace Friendica\Core\Cache;
use Friendica\Core\Cache\Enum\Duration;
/**
* This interface defines methods for Memory-Caches only
*/

View file

@ -19,10 +19,14 @@
*
*/
namespace Friendica\Core\Cache;
namespace Friendica\Core\Cache\Type;
use Exception;
use Friendica\Core\BaseCache;
use Friendica\Core\Cache\Enum\Duration;
use Friendica\Core\Cache\IMemoryCache;
use Friendica\Core\Cache\Type\TraitCompareDelete;
use Friendica\Core\Cache\Type\TraitCompareSet;
use Friendica\Core\Cache\Enum\Type;
/**
* APCu Cache.

View file

@ -19,9 +19,12 @@
*
*/
namespace Friendica\Core\Cache;
namespace Friendica\Core\Cache\Type;
use Friendica\Core\BaseCache;
use Friendica\Core\Cache\Enum\Duration;
use Friendica\Core\Cache\IMemoryCache;
use Friendica\Core\Cache\Type\TraitCompareDelete;
use Friendica\Core\Cache\Enum\Type;
/**
* Implementation of the IMemoryCache mainly for testing purpose

View file

@ -19,7 +19,7 @@
*
*/
namespace Friendica\Core;
namespace Friendica\Core\Cache\Type;
use Friendica\Core\Cache\ICache;

View file

@ -19,11 +19,13 @@
*
*/
namespace Friendica\Core\Cache;
namespace Friendica\Core\Cache\Type;
use Friendica\Core\Cache\Enum\Duration;
use Friendica\Core\Cache\ICache;
use Friendica\Core\Cache\Enum\Type;
use Friendica\Database\Database;
use Friendica\Util\DateTimeFormat;
use Friendica\Core\BaseCache;
/**
* Database Cache

View file

@ -19,10 +19,15 @@
*
*/
namespace Friendica\Core\Cache;
namespace Friendica\Core\Cache\Type;
use Exception;
use Friendica\Core\BaseCache;
use Friendica\Core\Cache\Enum\Duration;
use Friendica\Core\Cache\IMemoryCache;
use Friendica\Core\Cache\Type\TraitCompareDelete;
use Friendica\Core\Cache\Type\TraitCompareSet;
use Friendica\Core\Cache\Type\TraitMemcacheCommand;
use Friendica\Core\Cache\Enum\Type;
use Friendica\Core\Config\IConfig;
use Memcache;

View file

@ -19,10 +19,15 @@
*
*/
namespace Friendica\Core\Cache;
namespace Friendica\Core\Cache\Type;
use Exception;
use Friendica\Core\BaseCache;
use Friendica\Core\Cache\Enum\Duration;
use Friendica\Core\Cache\IMemoryCache;
use Friendica\Core\Cache\Type\TraitCompareDelete;
use Friendica\Core\Cache\Type\TraitCompareSet;
use Friendica\Core\Cache\Type\TraitMemcacheCommand;
use Friendica\Core\Cache\Enum\Type;
use Friendica\Core\Config\IConfig;
use Memcached;
use Psr\Log\LoggerInterface;

View file

@ -19,9 +19,11 @@
*
*/
namespace Friendica\Core\Cache;
namespace Friendica\Core\Cache\Type;
use Friendica\Core\System;
use Friendica\Core\Cache\Enum\Duration;
use Friendica\Core\Cache\ICache;
use Friendica\Core\Cache\IMemoryCache;
use Friendica\Util\Profiler;
/**

View file

@ -19,10 +19,12 @@
*
*/
namespace Friendica\Core\Cache;
namespace Friendica\Core\Cache\Type;
use Exception;
use Friendica\Core\BaseCache;
use Friendica\Core\Cache\Enum\Duration;
use Friendica\Core\Cache\IMemoryCache;
use Friendica\Core\Cache\Enum\Type;
use Friendica\Core\Config\IConfig;
use Redis;

View file

@ -19,7 +19,9 @@
*
*/
namespace Friendica\Core\Cache;
namespace Friendica\Core\Cache\Type;
use Friendica\Core\Cache\Enum\Duration;
/**
* Trait TraitCompareSetDelete

View file

@ -19,7 +19,9 @@
*
*/
namespace Friendica\Core\Cache;
namespace Friendica\Core\Cache\Type;
use Friendica\Core\Cache\Enum\Duration;
/**
* Trait TraitCompareSetDelete

View file

@ -19,7 +19,7 @@
*
*/
namespace Friendica\Core\Cache;
namespace Friendica\Core\Cache\Type;
use Friendica\Network\HTTPException\InternalServerErrorException;

View file

@ -22,7 +22,7 @@
namespace Friendica\Core\Lock;
use Friendica\Core\BaseLock;
use Friendica\Core\Cache\Duration;
use Friendica\Core\Cache\Enum\Duration;
use Friendica\Core\Cache\IMemoryCache;
class CacheLock extends BaseLock

View file

@ -22,7 +22,7 @@
namespace Friendica\Core\Lock;
use Friendica\Core\BaseLock;
use Friendica\Core\Cache\Duration;
use Friendica\Core\Cache\Enum\Duration;
use Friendica\Database\Database;
use Friendica\Util\DateTimeFormat;

View file

@ -21,7 +21,7 @@
namespace Friendica\Core\Lock;
use Friendica\Core\Cache\Duration;
use Friendica\Core\Cache\Enum\Duration;
/**
* Lock Interface

View file

@ -22,7 +22,7 @@
namespace Friendica\Core\Lock;
use Friendica\Core\BaseLock;
use Friendica\Core\Cache\Duration;
use Friendica\Core\Cache\Enum\Duration;
class SemaphoreLock extends BaseLock
{

View file

@ -21,7 +21,7 @@
namespace Friendica\Core\Lock;
use Friendica\Core\Cache\Type as CacheType;
use Friendica\Core\Cache\Enum\Type as CacheType;
/**
* Enumeration for lock types

View file

@ -132,7 +132,7 @@ class Update
// Compare the current structure with the defined structure
// If the Lock is acquired, never release it automatically to avoid double updates
if (DI::lock()->acquire('dbupdate', 0, Cache\Duration::INFINITE)) {
if (DI::lock()->acquire('dbupdate', 0, Cache\Enum\Duration::INFINITE)) {
Logger::notice('Update starting.', ['from' => $stored, 'to' => $current]);
@ -246,7 +246,7 @@ class Update
// If the update fails or times-out completely you may need to
// delete the config entry to try again.
if (DI::lock()->acquire('dbupdate_function', 120, Cache\Duration::INFINITE)) {
if (DI::lock()->acquire('dbupdate_function', 120, Cache\Enum\Duration::INFINITE)) {
// call the specific update
Logger::notice('Pre update function start.', ['function' => $funcname]);

View file

@ -21,8 +21,9 @@
namespace Friendica\Factory;
use Friendica\Core\Cache\Factory\CacheFactory;
use Friendica\Core\Cache\IMemoryCache;
use Friendica\Core\Cache\Type;
use Friendica\Core\Cache\Enum\Type;
use Friendica\Core\Config\IConfig;
use Friendica\Core\Lock;
use Friendica\Database\Database;

View file

@ -23,7 +23,7 @@ namespace Friendica\Factory;
use Friendica\App;
use Friendica\Core\Cache\ICache;
use Friendica\Core\Cache\Type;
use Friendica\Core\Cache\Enum\Type;
use Friendica\Core\Config\IConfig;
use Friendica\Core\Session;
use Friendica\Core\System;

View file

@ -22,7 +22,7 @@
namespace Friendica\Model;
use Friendica\Content\Text\HTML;
use Friendica\Core\Cache\Duration;
use Friendica\Core\Cache\Enum\Duration;
use Friendica\Core\Logger;
use Friendica\Core\System;
use Friendica\Database\DBA;

View file

@ -21,7 +21,7 @@
namespace Friendica\Model;
use Friendica\Core\Cache\Duration;
use Friendica\Core\Cache\Enum\Duration;
use Friendica\Core\Logger;
use Friendica\Core\System;
use Friendica\Database\DBA;

View file

@ -24,7 +24,7 @@ namespace Friendica\Model;
use Friendica\App;
use Friendica\Content\Text\BBCode;
use Friendica\Content\Widget\ContactBlock;
use Friendica\Core\Cache\Duration;
use Friendica\Core\Cache\Enum\Duration;
use Friendica\Core\Hook;
use Friendica\Core\Logger;
use Friendica\Core\Protocol;

View file

@ -22,7 +22,7 @@
namespace Friendica\Model;
use Friendica\Content\Text\BBCode;
use Friendica\Core\Cache\Duration;
use Friendica\Core\Cache\Enum\Duration;
use Friendica\Core\Logger;
use Friendica\Core\Protocol;
use Friendica\Core\System;

View file

@ -25,7 +25,7 @@ use Friendica\Content\Nav;
use Friendica\Content\Pager;
use Friendica\Content\Text\HTML;
use Friendica\Content\Widget;
use Friendica\Core\Cache\Duration;
use Friendica\Core\Cache\Enum\Duration;
use Friendica\Core\Logger;
use Friendica\Core\Renderer;
use Friendica\Core\Search;

View file

@ -23,7 +23,7 @@ namespace Friendica\Protocol\ActivityPub;
use Friendica\Content\Feature;
use Friendica\Content\Text\BBCode;
use Friendica\Core\Cache\Duration;
use Friendica\Core\Cache\Enum\Duration;
use Friendica\Core\Logger;
use Friendica\Core\Protocol;
use Friendica\Core\System;

View file

@ -24,7 +24,7 @@ namespace Friendica\Protocol;
use Friendica\Content\Feature;
use Friendica\Content\Text\BBCode;
use Friendica\Content\Text\Markdown;
use Friendica\Core\Cache\Duration;
use Friendica\Core\Cache\Enum\Duration;
use Friendica\Core\Logger;
use Friendica\Core\Protocol;
use Friendica\Core\System;

View file

@ -26,7 +26,7 @@ use DOMXPath;
use Friendica\Content\PageInfo;
use Friendica\Content\Text\BBCode;
use Friendica\Content\Text\HTML;
use Friendica\Core\Cache\Duration;
use Friendica\Core\Cache\Enum\Duration;
use Friendica\Core\Logger;
use Friendica\Core\Protocol;
use Friendica\Database\DBA;

View file

@ -25,7 +25,7 @@ use DOMDocument;
use DOMXPath;
use Friendica\Content\Text\BBCode;
use Friendica\Content\Text\HTML;
use Friendica\Core\Cache\Duration;
use Friendica\Core\Cache\Enum\Duration;
use Friendica\Core\Logger;
use Friendica\Core\Protocol;
use Friendica\Database\DBA;

View file

@ -21,7 +21,7 @@
namespace Friendica\Util;
use Friendica\Core\Cache\Duration;
use Friendica\Core\Cache\Enum\Duration;
use Friendica\Core\Logger;
use Exception;
use Friendica\DI;

View file

@ -21,7 +21,7 @@
namespace Friendica\Worker;
use Friendica\Core\Cache\Duration;
use Friendica\Core\Cache\Enum\Duration;
use Friendica\Core\Logger;
use Friendica\Core\Search;
use Friendica\DI;

View file

@ -158,13 +158,13 @@ return [
]
],
Cache\ICache::class => [
'instanceOf' => Factory\CacheFactory::class,
'instanceOf' => Cache\Factory\CacheFactory::class,
'call' => [
['create', [], Dice::CHAIN_CALL],
],
],
Cache\IMemoryCache::class => [
'instanceOf' => Factory\CacheFactory::class,
'instanceOf' => Cache\Factory\CacheFactory::class,
'call' => [
['create', [], Dice::CHAIN_CALL],
],

View file

@ -21,7 +21,7 @@
namespace Friendica\Test\src\Core\Cache;
use Friendica\Core\Cache\APCuCache;
use Friendica\Core\Cache\Type\APCuCache;
/**
* @group APCU

View file

@ -21,7 +21,7 @@
namespace Friendica\Test\src\Core\Cache;
use Friendica\Core\Cache\ArrayCache;
use Friendica\Core\Cache\Type\ArrayCache;
class ArrayCacheTest extends MemoryCacheTest
{

View file

@ -60,7 +60,7 @@ class DatabaseCacheTest extends CacheTest
$dba = new StaticDatabase($configCache, $profiler, $logger);
$this->cache = new Cache\DatabaseCache('database', $dba);
$this->cache = new Cache\Type\DatabaseCache('database', $dba);
return $this->cache;
}

View file

@ -22,7 +22,7 @@
namespace Friendica\Test\src\Core\Cache;
use Exception;
use Friendica\Core\Cache\MemcacheCache;
use Friendica\Core\Cache\Type\MemcacheCache;
use Friendica\Core\Config\IConfig;
use Mockery;

View file

@ -22,7 +22,7 @@
namespace Friendica\Test\src\Core\Cache;
use Exception;
use Friendica\Core\Cache\MemcachedCache;
use Friendica\Core\Cache\Type\MemcachedCache;
use Friendica\Core\Config\IConfig;
use Mockery;
use Psr\Log\NullLogger;

View file

@ -22,7 +22,7 @@
namespace Friendica\Test\src\Core\Cache;
use Exception;
use Friendica\Core\Cache\RedisCache;
use Friendica\Core\Cache\Type\RedisCache;
use Friendica\Core\Config\IConfig;
use Mockery;
@ -58,7 +58,7 @@ class RedisCacheTest extends MemoryCacheTest
->andReturn(null);
try {
$this->cache = new RedisCache($host, $configMock);
$this->cache = new \Friendica\Core\Cache\Type\RedisCache($host, $configMock);
} catch (Exception $e) {
static::markTestSkipped('Redis is not available. Failure: ' . $e->getMessage());
}

View file

@ -21,7 +21,7 @@
namespace Friendica\Test\src\Core\Lock;
use Friendica\Core\Cache\APCuCache;
use Friendica\Core\Cache\Type\APCuCache;
use Friendica\Core\Lock\CacheLock;
/**

View file

@ -21,7 +21,7 @@
namespace Friendica\Test\src\Core\Lock;
use Friendica\Core\Cache\ArrayCache;
use Friendica\Core\Cache\Type\ArrayCache;
use Friendica\Core\Lock\CacheLock;
class ArrayCacheLockTest extends LockTest

View file

@ -22,7 +22,7 @@
namespace Friendica\Test\src\Core\Lock;
use Exception;
use Friendica\Core\Cache\MemcacheCache;
use Friendica\Core\Cache\Type\MemcacheCache;
use Friendica\Core\Config\IConfig;
use Friendica\Core\Lock\CacheLock;
use Mockery;

View file

@ -22,7 +22,7 @@
namespace Friendica\Test\src\Core\Lock;
use Exception;
use Friendica\Core\Cache\MemcachedCache;
use Friendica\Core\Cache\Type\MemcachedCache;
use Friendica\Core\Config\IConfig;
use Friendica\Core\Lock\CacheLock;
use Mockery;

View file

@ -22,7 +22,7 @@
namespace Friendica\Test\src\Core\Lock;
use Exception;
use Friendica\Core\Cache\RedisCache;
use Friendica\Core\Cache\Type\RedisCache;
use Friendica\Core\Config\IConfig;
use Friendica\Core\Lock\CacheLock;
use Mockery;