mirror of
https://git.friendi.ca/friendica/friendica.git
synced 2025-06-17 12:05:15 +02:00
Merge branch 'develop' into phpstan-level-3
This commit is contained in:
commit
63558f92eb
50 changed files with 1362 additions and 611 deletions
|
@ -53,4 +53,11 @@ interface ICanCacheInMemory extends ICanCache
|
|||
* @throws CachePersistenceException In case the underlying cache driver has errors during persistence
|
||||
*/
|
||||
public function compareDelete(string $key, $value): bool;
|
||||
|
||||
/**
|
||||
* Returns some basic statistics of the used Cache instance
|
||||
*
|
||||
* @return array Returns an associative array of statistics
|
||||
*/
|
||||
public function getStats(): array;
|
||||
}
|
||||
|
|
|
@ -16,10 +16,9 @@ use Friendica\Core\Cache\Exception\InvalidCacheDriverException;
|
|||
*/
|
||||
class APCuCache extends AbstractCache implements ICanCacheInMemory
|
||||
{
|
||||
const NAME = 'apcu';
|
||||
|
||||
use CompareSetTrait;
|
||||
use CompareDeleteTrait;
|
||||
const NAME = 'apcu';
|
||||
|
||||
/**
|
||||
* @throws InvalidCacheDriverException
|
||||
|
@ -147,4 +146,19 @@ class APCuCache extends AbstractCache implements ICanCacheInMemory
|
|||
|
||||
return true;
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public function getStats(): array
|
||||
{
|
||||
$apcu = apcu_cache_info();
|
||||
$sma = apcu_sma_info();
|
||||
|
||||
return [
|
||||
'entries' => $apcu['num_entries'] ?? null,
|
||||
'used_memory' => $apcu['mem_size'] ?? null,
|
||||
'hits' => $apcu['num_hits'] ?? null,
|
||||
'misses' => $apcu['num_misses'] ?? null,
|
||||
'avail_mem' => $sma['avail_mem'] ?? null,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,9 +15,8 @@ use Friendica\Core\Cache\Enum;
|
|||
*/
|
||||
class ArrayCache extends AbstractCache implements ICanCacheInMemory
|
||||
{
|
||||
const NAME = 'array';
|
||||
|
||||
use CompareDeleteTrait;
|
||||
const NAME = 'array';
|
||||
|
||||
/** @var array Array with the cached data */
|
||||
protected $cachedData = [];
|
||||
|
@ -96,4 +95,10 @@ class ArrayCache extends AbstractCache implements ICanCacheInMemory
|
|||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public function getStats(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,11 +19,10 @@ use Memcache;
|
|||
*/
|
||||
class MemcacheCache extends AbstractCache implements ICanCacheInMemory
|
||||
{
|
||||
const NAME = 'memcache';
|
||||
|
||||
use CompareSetTrait;
|
||||
use CompareDeleteTrait;
|
||||
use MemcacheCommandTrait;
|
||||
const NAME = 'memcache';
|
||||
|
||||
/**
|
||||
* @var Memcache
|
||||
|
@ -156,4 +155,21 @@ class MemcacheCache extends AbstractCache implements ICanCacheInMemory
|
|||
$cacheKey = $this->getCacheKey($key);
|
||||
return $this->memcache->add($cacheKey, serialize($value), MEMCACHE_COMPRESSED, $ttl);
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public function getStats(): array
|
||||
{
|
||||
$stats = $this->memcache->getStats();
|
||||
|
||||
return [
|
||||
'version' => $stats['version'] ?? null,
|
||||
'entries' => $stats['curr_items'] ?? null,
|
||||
'used_memory' => $stats['bytes'] ?? null,
|
||||
'uptime' => $stats['uptime'] ?? null,
|
||||
'connected_clients' => $stats['curr_connections'] ?? null,
|
||||
'hits' => $stats['get_hits'] ?? null,
|
||||
'misses' => $stats['get_misses'] ?? null,
|
||||
'evictions' => $stats['evictions'] ?? null,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,11 +20,10 @@ use Psr\Log\LoggerInterface;
|
|||
*/
|
||||
class MemcachedCache extends AbstractCache implements ICanCacheInMemory
|
||||
{
|
||||
const NAME = 'memcached';
|
||||
|
||||
use CompareSetTrait;
|
||||
use CompareDeleteTrait;
|
||||
use MemcacheCommandTrait;
|
||||
const NAME = 'memcached';
|
||||
|
||||
/**
|
||||
* @var \Memcached
|
||||
|
@ -172,4 +171,27 @@ class MemcachedCache extends AbstractCache implements ICanCacheInMemory
|
|||
$cacheKey = $this->getCacheKey($key);
|
||||
return $this->memcached->add($cacheKey, $value, $ttl);
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public function getStats(): array
|
||||
{
|
||||
$stats = $this->memcached->getStats();
|
||||
|
||||
// get statistics of the first instance
|
||||
foreach ($stats as $value) {
|
||||
$stats = $value;
|
||||
break;
|
||||
}
|
||||
|
||||
return [
|
||||
'version' => $stats['version'] ?? null,
|
||||
'entries' => $stats['curr_items'] ?? null,
|
||||
'used_memory' => $stats['bytes'] ?? null,
|
||||
'uptime' => $stats['uptime'] ?? null,
|
||||
'connected_clients' => $stats['curr_connections'] ?? null,
|
||||
'hits' => $stats['get_hits'] ?? null,
|
||||
'misses' => $stats['get_misses'] ?? null,
|
||||
'evictions' => $stats['evictions'] ?? null,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -166,4 +166,14 @@ class ProfilerCacheDecorator implements ICanCache, ICanCacheInMemory
|
|||
{
|
||||
return $this->cache->getName() . ' (with profiler)';
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public function getStats(): array
|
||||
{
|
||||
if ($this->cache instanceof ICanCacheInMemory) {
|
||||
return $this->cache->getStats();
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -207,4 +207,21 @@ class RedisCache extends AbstractCache implements ICanCacheInMemory
|
|||
$this->redis->unwatch();
|
||||
return false;
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public function getStats(): array
|
||||
{
|
||||
$info = $this->redis->info();
|
||||
|
||||
return [
|
||||
'version' => $info['redis_version'] ?? null,
|
||||
'entries' => $this->redis->dbSize() ?? null,
|
||||
'used_memory' => $info['used_memory'] ?? null,
|
||||
'connected_clients' => $info['connected_clients'] ?? null,
|
||||
'uptime' => $info['uptime_in_seconds'] ?? null,
|
||||
'hits' => $info['keyspace_hits'] ?? null,
|
||||
'misses' => $info['keyspace_misses'] ?? null,
|
||||
'evictions' => $info['evicted_keys'] ?? null,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
|
||||
namespace Friendica\Core\Lock\Type;
|
||||
|
||||
use Friendica\Core\Cache\Capability\ICanCache;
|
||||
use Friendica\Core\Cache\Capability\ICanCacheInMemory;
|
||||
use Friendica\Core\Cache\Enum\Duration;
|
||||
use Friendica\Core\Cache\Exception\CachePersistenceException;
|
||||
|
@ -156,6 +155,16 @@ class CacheLock extends AbstractLock
|
|||
return $success;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns stats about the cache provider
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getCacheStats(): array
|
||||
{
|
||||
return $this->cache->getStats();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $key The original key
|
||||
*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue