* @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;
}
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,
+ ];
+ }
}
return false;
}
}
+
+ /** {@inheritDoc} */
+ public function getStats(): array
+ {
+ return [];
+ }
}
$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,
+ ];
+ }
}
$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,
+ ];
+ }
}
{
return $this->cache->getName() . ' (with profiler)';
}
+
+ /** {@inheritDoc} */
+ public function getStats(): array
+ {
+ if ($this->cache instanceof ICanCacheInMemory) {
+ return $this->cache->getStats();
+ } else {
+ return [];
+ }
+ }
}
$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,
+ ];
+ }
}
return $success;
}
+ /**
+ * Returns stats about the cache provider
+ *
+ * @return array
+ */
+ public function getCacheStats(): array
+ {
+ return $this->cache->getStats();
+ }
+
/**
* @param string $key The original key
*
$this->cache->clear(false);
parent::tearDown();
}
+
+ /**
+ * @small
+ */
+ public function testStats()
+ {
+ $stats = $this->instance->getStats();
+
+ self::assertNotNull($stats['entries']);
+ self::assertNotNull($stats['used_memory']);
+ self::assertNotNull($stats['hits']);
+ self::assertNotNull($stats['misses']);
+ self::assertNotNull($stats['avail_mem']);
+ }
}
{
static::markTestIncomplete('Race condition because of too fast getAllKeys() which uses a workaround');
}
+
+ /**
+ * @small
+ */
+ public function testStats()
+ {
+ $stats = $this->instance->getStats();
+
+ self::assertNotNull($stats['version']);
+ self::assertIsNumeric($stats['hits']);
+ self::assertIsNumeric($stats['misses']);
+ self::assertIsNumeric($stats['evictions']);
+ self::assertIsNumeric($stats['entries']);
+ self::assertIsNumeric($stats['used_memory']);
+ self::assertGreaterThan(0, $stats['connected_clients']);
+ self::assertGreaterThan(0, $stats['uptime']);
+ }
}
{
static::markTestIncomplete('Race condition because of too fast getAllKeys() which uses a workaround');
}
+
+ /**
+ * @small
+ */
+ public function testStats()
+ {
+ $stats = $this->instance->getStats();
+
+ self::assertNotNull($stats['version']);
+ self::assertIsNumeric($stats['hits']);
+ self::assertIsNumeric($stats['misses']);
+ self::assertIsNumeric($stats['evictions']);
+ self::assertIsNumeric($stats['entries']);
+ self::assertIsNumeric($stats['used_memory']);
+ self::assertGreaterThan(0, $stats['connected_clients']);
+ self::assertGreaterThan(0, $stats['uptime']);
+ }
}
$this->cache->clear(false);
parent::tearDown();
}
+
+ /**
+ * @small
+ */
+ public function testStats()
+ {
+ $stats = $this->instance->getStats();
+
+ self::assertNotNull($stats['version']);
+ self::assertIsNumeric($stats['hits']);
+ self::assertIsNumeric($stats['misses']);
+ self::assertIsNumeric($stats['evictions']);
+ self::assertIsNumeric($stats['entries']);
+ self::assertIsNumeric($stats['used_memory']);
+ self::assertGreaterThan(0, $stats['connected_clients']);
+ self::assertGreaterThan(0, $stats['uptime']);
+ }
}