friendica/src/Core/Cache/Capability/ICanCache.php

94 lines
2.6 KiB
PHP
Raw Normal View History

<?php
2020-02-09 15:45:36 +01:00
/**
2021-03-29 08:40:20 +02:00
* @copyright Copyright (C) 2010-2021, the Friendica project
2020-02-09 15:45:36 +01:00
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
2021-10-26 21:44:29 +02:00
namespace Friendica\Core\Cache\Capability;
use Friendica\Core\Cache\Enum\Duration;
2021-10-26 21:44:29 +02:00
use Friendica\Core\Cache\Exception\CachePersistenceException;
/**
2021-10-26 21:44:29 +02:00
* Interface for caches
*/
2021-10-26 21:44:29 +02:00
interface ICanCache
{
2018-09-26 04:52:32 +02:00
/**
* Lists all cache keys
*
2021-10-26 21:44:29 +02:00
* @param string|null prefix optional a prefix to search
*
2018-10-07 22:14:05 +02:00
* @return array Empty if it isn't supported by the cache driver
2018-09-26 04:52:32 +02:00
*/
2021-10-26 21:44:29 +02:00
public function getAllKeys(?string $prefix = null): array;
2018-09-26 04:52:32 +02:00
/**
2018-07-05 07:59:56 +02:00
* Fetches cached data according to the key
*
* @param string $key The key to the cached data
*
* @return mixed Cached $value or "null" if not found
2021-10-26 21:44:29 +02:00
*
* @throws CachePersistenceException In case the underlying cache driver has errors during persistence
*/
2021-10-26 21:44:29 +02:00
public function get(string $key);
/**
2018-07-05 07:59:56 +02:00
* Stores data in the cache identified by the key. The input $value can have multiple formats.
*
2021-10-26 21:44:29 +02:00
* @param string $key The cache key
* @param mixed $value The value to store
* @param integer $ttl The cache lifespan, must be one of the Cache constants
*
* @return bool
2021-10-26 21:44:29 +02:00
*
* @throws CachePersistenceException In case the underlying cache driver has errors during persistence
*/
2021-10-26 21:44:29 +02:00
public function set(string $key, $value, int $ttl = Duration::FIVE_MINUTES): bool;
/**
2018-07-05 07:59:56 +02:00
* Delete a key from the cache
*
2021-10-26 21:44:29 +02:00
* @param string $key The cache key
*
* @return bool
2021-10-26 21:44:29 +02:00
*
* @throws CachePersistenceException In case the underlying cache driver has errors during persistence
*/
2021-10-26 21:44:29 +02:00
public function delete(string $key): bool;
/**
2018-07-05 07:59:56 +02:00
* Remove outdated data from the cache
2021-10-26 21:44:29 +02:00
*
* @param boolean $outdated just remove outdated values
*
* @return bool
2021-10-26 21:44:29 +02:00
*
* @throws CachePersistenceException In case the underlying cache driver has errors during persistence
*/
2021-10-26 21:44:29 +02:00
public function clear(bool $outdated = true): bool;
2019-08-04 16:13:53 +02:00
/**
* Returns the name of the current cache
*
* @return string
*/
2021-10-26 21:44:29 +02:00
public function getName(): string;
}