use Friendica\App;
use Friendica\Content\ForumManager;
use Friendica\Content\Text\BBCode;
-use Friendica\Core\Cache\Cache;
+use Friendica\Core\Cache\Duration;
use Friendica\Core\Config;
use Friendica\Core\Hook;
use Friendica\Core\L10n;
DBA::escape(DateTimeFormat::utcNow())
);
if (DBA::isResult($ev)) {
- DI::cache()->set($cachekey, $ev, Cache::HOUR);
+ DI::cache()->set($cachekey, $ev, Duration::HOUR);
}
}
use Asika\SimpleConsole\CommandArgsException;
use Friendica\App;
-use Friendica\Core\Cache\Cache as CacheClass;
+use Friendica\Core\Cache\Duration;
use Friendica\Core\Cache\ICache;
use RuntimeException;
if (count($this->args) >= 3) {
$key = $this->getArgument(1);
$value = $this->getArgument(2);
- $duration = intval($this->getArgument(3, CacheClass::FIVE_MINUTES));
+ $duration = intval($this->getArgument(3, Duration::FIVE_MINUTES));
if (is_array($this->cache->get($key))) {
throw new RuntimeException("$key is an array and can't be set using this command.");
use DOMText;
use DOMXPath;
use Exception;
-use Friendica\Core\Cache\Cache;
+use Friendica\Core\Cache\Duration;
use Friendica\Core\Config;
use Friendica\Core\Hook;
use Friendica\Core\L10n;
'content' => $json_string,
'created' => DateTimeFormat::utcNow()
], true);
- $cache_ttl = Cache::DAY;
+ $cache_ttl = Duration::DAY;
} else {
- $cache_ttl = Cache::FIVE_MINUTES;
+ $cache_ttl = Duration::FIVE_MINUTES;
}
DI::cache()->set($cache_key, $json_string, $cache_ttl);
--- /dev/null
+<?php
+
+namespace Friendica\Core;
+
+use Friendica\Core\Cache\ICache;
+
+/**
+ * Abstract class for common used functions
+ */
+abstract class BaseCache implements ICache
+{
+ /**
+ * @var string The hostname
+ */
+ private $hostName;
+
+ public function __construct(string $hostName)
+ {
+ $this->hostName = $hostName;
+ }
+
+ /**
+ * Returns the prefix (to avoid namespace conflicts)
+ *
+ * @return string
+ * @throws \Exception
+ */
+ protected function getPrefix()
+ {
+ // We fetch with the hostname as key to avoid problems with other applications
+ return $this->hostName;
+ }
+
+ /**
+ * @param string $key The original key
+ * @return string The cache key used for the cache
+ * @throws \Exception
+ */
+ protected function getCacheKey($key)
+ {
+ return $this->getPrefix() . ":" . $key;
+ }
+
+ /**
+ * @param array $keys A list of cached keys
+ * @return array A list of original keys
+ */
+ protected function getOriginalKeys($keys)
+ {
+ if (empty($keys)) {
+ return [];
+ } else {
+ // Keys are prefixed with the node hostname, let's remove it
+ array_walk($keys, function (&$value) {
+ $value = preg_replace('/^' . $this->hostName . ':/', '', $value);
+ });
+
+ sort($keys);
+
+ return $keys;
+ }
+ }
+
+ /**
+ * Filters the keys of an array with a given prefix
+ * Returns the filtered keys as an new array
+ *
+ * @param array $keys The keys, which should get filtered
+ * @param string|null $prefix The prefix (if null, all keys will get returned)
+ *
+ * @return array The filtered array with just the keys
+ */
+ protected function filterArrayKeysByPrefix(array $keys, string $prefix = null)
+ {
+ if (empty($prefix)) {
+ return $keys;
+ } else {
+ $result = [];
+
+ foreach ($keys as $key) {
+ if (strpos($key, $prefix) === 0) {
+ array_push($result, $key);
+ }
+ }
+
+ return $result;
+ }
+ }
+}
namespace Friendica\Core\Cache;
use Exception;
+use Friendica\Core\BaseCache;
/**
* APCu Cache.
*
* @author Philipp Holzer <admin@philipp.info>
*/
-class APCuCache extends Cache implements IMemoryCache
+class APCuCache extends BaseCache implements IMemoryCache
{
use TraitCompareSet;
use TraitCompareDelete;
/**
* (@inheritdoc)
*/
- public function set($key, $value, $ttl = Cache::FIVE_MINUTES)
+ public function set($key, $value, $ttl = Duration::FIVE_MINUTES)
{
$cachekey = $this->getCacheKey($key);
/**
* (@inheritdoc)
*/
- public function add($key, $value, $ttl = Cache::FIVE_MINUTES)
+ public function add($key, $value, $ttl = Duration::FIVE_MINUTES)
{
$cachekey = $this->getCacheKey($key);
$cached = serialize($value);
*/
public function getName()
{
- return self::TYPE_APCU;
+ return Type::APCU;
}
}
namespace Friendica\Core\Cache;
+use Friendica\Core\BaseCache;
+
/**
* Implementation of the IMemoryCache mainly for testing purpose
*
*
* @package Friendica\Core\Cache
*/
-class ArrayCache extends Cache implements IMemoryCache
+class ArrayCache extends BaseCache implements IMemoryCache
{
use TraitCompareDelete;
/**
* (@inheritdoc)
*/
- public function set($key, $value, $ttl = Cache::FIVE_MINUTES)
+ public function set($key, $value, $ttl = Duration::FIVE_MINUTES)
{
$this->cachedData[$key] = $value;
return true;
/**
* (@inheritdoc)
*/
- public function add($key, $value, $ttl = Cache::FIVE_MINUTES)
+ public function add($key, $value, $ttl = Duration::FIVE_MINUTES)
{
if (isset($this->cachedData[$key])) {
return false;
/**
* (@inheritdoc)
*/
- public function compareSet($key, $oldValue, $newValue, $ttl = Cache::FIVE_MINUTES)
+ public function compareSet($key, $oldValue, $newValue, $ttl = Duration::FIVE_MINUTES)
{
if ($this->get($key) === $oldValue) {
return $this->set($key, $newValue);
*/
public function getName()
{
- return self::TYPE_ARRAY;
+ return Type::ARRAY;
}
}
+++ /dev/null
-<?php
-
-namespace Friendica\Core\Cache;
-
-/**
- * Abstract class for common used functions
- *
- * Class AbstractCache
- *
- * @package Friendica\Core\Cache
- */
-abstract class Cache implements ICache
-{
- const TYPE_APCU = 'apcu';
- const TYPE_ARRAY = 'array';
- const TYPE_DATABASE = 'database';
- const TYPE_MEMCACHE = 'memcache';
- const TYPE_MEMCACHED = 'memcached';
- const TYPE_REDIS = 'redis';
-
- const MONTH = 2592000;
- const WEEK = 604800;
- const DAY = 86400;
- const HOUR = 3600;
- const HALF_HOUR = 1800;
- const QUARTER_HOUR = 900;
- const FIVE_MINUTES = 300;
- const MINUTE = 60;
- const INFINITE = 0;
-
- /**
- * @var string The hostname
- */
- private $hostName;
-
- public function __construct(string $hostName)
- {
- $this->hostName = $hostName;
- }
-
- /**
- * Returns the prefix (to avoid namespace conflicts)
- *
- * @return string
- * @throws \Exception
- */
- protected function getPrefix()
- {
- // We fetch with the hostname as key to avoid problems with other applications
- return $this->hostName;
- }
-
- /**
- * @param string $key The original key
- * @return string The cache key used for the cache
- * @throws \Exception
- */
- protected function getCacheKey($key)
- {
- return $this->getPrefix() . ":" . $key;
- }
-
- /**
- * @param array $keys A list of cached keys
- * @return array A list of original keys
- */
- protected function getOriginalKeys($keys)
- {
- if (empty($keys)) {
- return [];
- } else {
- // Keys are prefixed with the node hostname, let's remove it
- array_walk($keys, function (&$value) {
- $value = preg_replace('/^' . $this->hostName . ':/', '', $value);
- });
-
- sort($keys);
-
- return $keys;
- }
- }
-
- /**
- * Filters the keys of an array with a given prefix
- * Returns the filtered keys as an new array
- *
- * @param array $keys The keys, which should get filtered
- * @param string|null $prefix The prefix (if null, all keys will get returned)
- *
- * @return array The filtered array with just the keys
- */
- protected function filterArrayKeysByPrefix(array $keys, string $prefix = null)
- {
- if (empty($prefix)) {
- return $keys;
- } else {
- $result = [];
-
- foreach ($keys as $key) {
- if (strpos($key, $prefix) === 0) {
- array_push($result, $key);
- }
- }
-
- return $result;
- }
- }
-}
use Friendica\Database\Database;
use Friendica\Util\DateTimeFormat;
+use Friendica\Core\BaseCache;
/**
* Database Cache
*
* @author Hypolite Petovan <hypolite@mrpetovan.com>
*/
-class DatabaseCache extends Cache implements ICache
+class DatabaseCache extends BaseCache implements ICache
{
/**
* @var Database
/**
* (@inheritdoc)
*/
- public function set($key, $value, $ttl = Cache::FIVE_MINUTES)
+ public function set($key, $value, $ttl = Duration::FIVE_MINUTES)
{
if ($ttl > 0) {
$fields = [
*/
public function getName()
{
- return self::TYPE_DATABASE;
+ return Type::DATABASE;
}
}
--- /dev/null
+<?php
+
+namespace Friendica\Core\Cache;
+
+/**
+ * Enumeration for cache durations
+ */
+abstract class Duration
+{
+ const MONTH = 2592000;
+ const HOUR = 3600;
+ const HALF_HOUR = 1800;
+ const QUARTER_HOUR = 900;
+ const MINUTE = 60;
+ const WEEK = 604800;
+ const INFINITE = 0;
+ const DAY = 86400;
+ const FIVE_MINUTES = 300;
+}
*
* @return bool
*/
- public function set($key, $value, $ttl = Cache::FIVE_MINUTES);
+ public function set($key, $value, $ttl = Duration::FIVE_MINUTES);
/**
* Delete a key from the cache
* @param int $ttl The cache lifespan, must be one of the Cache constants
* @return bool
*/
- public function add($key, $value, $ttl = Cache::FIVE_MINUTES);
+ public function add($key, $value, $ttl = Duration::FIVE_MINUTES);
/**
* Compares if the old value is set and sets the new value
*
* @return bool
*/
- public function compareSet($key, $oldValue, $newValue, $ttl = Cache::FIVE_MINUTES);
+ public function compareSet($key, $oldValue, $newValue, $ttl = Duration::FIVE_MINUTES);
/**
* Compares if the old value is set and removes it
namespace Friendica\Core\Cache;
use Exception;
+use Friendica\Core\BaseCache;
use Friendica\Core\Config\IConfiguration;
use Memcache;
*
* @author Hypolite Petovan <hypolite@mrpetovan.com>
*/
-class MemcacheCache extends Cache implements IMemoryCache
+class MemcacheCache extends BaseCache implements IMemoryCache
{
use TraitCompareSet;
use TraitCompareDelete;
/**
* (@inheritdoc)
*/
- public function set($key, $value, $ttl = Cache::FIVE_MINUTES)
+ public function set($key, $value, $ttl = Duration::FIVE_MINUTES)
{
$cachekey = $this->getCacheKey($key);
/**
* (@inheritdoc)
*/
- public function add($key, $value, $ttl = Cache::FIVE_MINUTES)
+ public function add($key, $value, $ttl = Duration::FIVE_MINUTES)
{
$cachekey = $this->getCacheKey($key);
return $this->memcache->add($cachekey, serialize($value), MEMCACHE_COMPRESSED, $ttl);
*/
public function getName()
{
- return self::TYPE_MEMCACHE;
+ return Type::MEMCACHE;
}
}
namespace Friendica\Core\Cache;
use Exception;
+use Friendica\Core\BaseCache;
use Friendica\Core\Config\IConfiguration;
use Memcached;
use Psr\Log\LoggerInterface;
*
* @author Hypolite Petovan <hypolite@mrpetovan.com>
*/
-class MemcachedCache extends Cache implements IMemoryCache
+class MemcachedCache extends BaseCache implements IMemoryCache
{
use TraitCompareSet;
use TraitCompareDelete;
/**
* (@inheritdoc)
*/
- public function set($key, $value, $ttl = Cache::FIVE_MINUTES)
+ public function set($key, $value, $ttl = Duration::FIVE_MINUTES)
{
$cachekey = $this->getCacheKey($key);
/**
* (@inheritdoc)
*/
- public function add($key, $value, $ttl = Cache::FIVE_MINUTES)
+ public function add($key, $value, $ttl = Duration::FIVE_MINUTES)
{
$cachekey = $this->getCacheKey($key);
return $this->memcached->add($cachekey, $value, $ttl);
*/
public function getName()
{
- return self::TYPE_MEMCACHED;
+ return Type::MEMCACHED;
}
}
/**
* {@inheritDoc}
*/
- public function set($key, $value, $ttl = Cache::FIVE_MINUTES)
+ public function set($key, $value, $ttl = Duration::FIVE_MINUTES)
{
$time = microtime(true);
/**
* {@inheritDoc}
*/
- public function add($key, $value, $ttl = Cache::FIVE_MINUTES)
+ public function add($key, $value, $ttl = Duration::FIVE_MINUTES)
{
if ($this->cache instanceof IMemoryCache) {
$time = microtime(true);
/**
* {@inheritDoc}
*/
- public function compareSet($key, $oldValue, $newValue, $ttl = Cache::FIVE_MINUTES)
+ public function compareSet($key, $oldValue, $newValue, $ttl = Duration::FIVE_MINUTES)
{
if ($this->cache instanceof IMemoryCache) {
$time = microtime(true);
namespace Friendica\Core\Cache;
use Exception;
+use Friendica\Core\BaseCache;
use Friendica\Core\Config\IConfiguration;
use Redis;
* @author Hypolite Petovan <hypolite@mrpetovan.com>
* @author Roland Haeder <roland@mxchange.org>
*/
-class RedisCache extends Cache implements IMemoryCache
+class RedisCache extends BaseCache implements IMemoryCache
{
/**
* @var Redis
/**
* (@inheritdoc)
*/
- public function set($key, $value, $ttl = Cache::FIVE_MINUTES)
+ public function set($key, $value, $ttl = Duration::FIVE_MINUTES)
{
$cachekey = $this->getCacheKey($key);
/**
* (@inheritdoc)
*/
- public function add($key, $value, $ttl = Cache::FIVE_MINUTES)
+ public function add($key, $value, $ttl = Duration::FIVE_MINUTES)
{
$cachekey = $this->getCacheKey($key);
$cached = serialize($value);
/**
* (@inheritdoc)
*/
- public function compareSet($key, $oldValue, $newValue, $ttl = Cache::FIVE_MINUTES)
+ public function compareSet($key, $oldValue, $newValue, $ttl = Duration::FIVE_MINUTES)
{
$cachekey = $this->getCacheKey($key);
*/
public function getName()
{
- return self::TYPE_REDIS;
+ return Type::REDIS;
}
}
{
abstract public function get($key);
- abstract public function set($key, $value, $ttl = Cache::FIVE_MINUTES);
+ abstract public function set($key, $value, $ttl = Duration::FIVE_MINUTES);
abstract public function delete($key);
- abstract public function add($key, $value, $ttl = Cache::FIVE_MINUTES);
+ abstract public function add($key, $value, $ttl = Duration::FIVE_MINUTES);
/**
* NonNative - Compares if the old value is set and removes it
{
abstract public function get($key);
- abstract public function set($key, $value, $ttl = Cache::FIVE_MINUTES);
+ abstract public function set($key, $value, $ttl = Duration::FIVE_MINUTES);
abstract public function delete($key);
- abstract public function add($key, $value, $ttl = Cache::FIVE_MINUTES);
+ abstract public function add($key, $value, $ttl = Duration::FIVE_MINUTES);
/**
* NonNative - Compares if the old value is set and sets the new value
*
* @return bool
*/
- public function compareSet($key, $oldValue, $newValue, $ttl = Cache::FIVE_MINUTES) {
+ public function compareSet($key, $oldValue, $newValue, $ttl = Duration::FIVE_MINUTES) {
if ($this->add($key . "_lock", true)) {
if ($this->get($key) === $oldValue) {
$this->set($key, $newValue, $ttl);
--- /dev/null
+<?php
+
+namespace Friendica\Core\Cache;
+
+/**
+ * Enumeration for cache types
+ */
+abstract class Type
+{
+ const APCU = 'apcu';
+ const REDIS = 'redis';
+ const ARRAY = 'array';
+ const MEMCACHE = 'memcache';
+ const DATABASE = 'database';
+ const MEMCACHED = 'memcached';
+}
/**
* (@inheritdoc)
*/
- public function acquire($key, $timeout = 120, $ttl = Cache\Cache::FIVE_MINUTES)
+ public function acquire($key, $timeout = 120, $ttl = Cache\Duration::FIVE_MINUTES)
{
$got_lock = false;
$start = time();
namespace Friendica\Core\Lock;
-use Friendica\Core\Cache\Cache;
+use Friendica\Core\Cache\Duration;
use Friendica\Database\Database;
use Friendica\Util\DateTimeFormat;
/**
* (@inheritdoc)
*/
- public function acquire($key, $timeout = 120, $ttl = Cache::FIVE_MINUTES)
+ public function acquire($key, $timeout = 120, $ttl = Duration::FIVE_MINUTES)
{
$got_lock = false;
$start = time();
*
* @return boolean Was the lock successful?
*/
- public function acquire($key, $timeout = 120, $ttl = Cache\Cache::FIVE_MINUTES);
+ public function acquire($key, $timeout = 120, $ttl = Cache\Duration::FIVE_MINUTES);
/**
* Releases a lock if it was set by us
namespace Friendica\Core\Lock;
-use Friendica\Core\Cache\Cache;
+use Friendica\Core\Cache\Type;
/**
* Class AbstractLock
*/
abstract class Lock implements ILock
{
- const TYPE_DATABASE = Cache::TYPE_DATABASE;
+ const TYPE_DATABASE = Type::DATABASE;
const TYPE_SEMAPHORE = 'semaphore';
/**
/**
* (@inheritdoc)
*/
- public function acquire($key, $timeout = 120, $ttl = Cache\Cache::FIVE_MINUTES)
+ public function acquire($key, $timeout = 120, $ttl = Cache\Duration::FIVE_MINUTES)
{
self::$semaphore[$key] = sem_get(self::semaphoreKey($key));
if (!empty(self::$semaphore[$key])) {
use Friendica\Database\DBStructure;
use Friendica\DI;
use Friendica\Util\Strings;
-use Friendica\Core\Cache\Cache;
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', 120, Cache::INFINITE)) {
+ if (DI::lock()->acquire('dbupdate', 120, Cache\Duration::INFINITE)) {
// Checks if the build changed during Lock acquiring (so no double update occurs)
$retryBuild = Config::get('system', 'build', null, true);
// 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::INFINITE)) {
+ if (DI::lock()->acquire('dbupdate_function', 120, Cache\Duration::INFINITE)) {
// call the specific update
$retval = $funcname();
/**
* @var string The default cache if nothing set
*/
- const DEFAULT_TYPE = Cache\Cache::TYPE_DATABASE;
+ const DEFAULT_TYPE = Cache\Type::DATABASE;
/**
* @var IConfiguration The IConfiguration to read parameters out of the config
}
switch ($type) {
- case Cache\Cache::TYPE_MEMCACHE:
+ case Cache\Type::MEMCACHE:
$cache = new Cache\MemcacheCache($this->hostname, $this->config);
break;
- case Cache\Cache::TYPE_MEMCACHED:
+ case Cache\Type::MEMCACHED:
$cache = new Cache\MemcachedCache($this->hostname, $this->config, $this->logger);
break;
- case Cache\Cache::TYPE_REDIS:
+ case Cache\Type::REDIS:
$cache = new Cache\RedisCache($this->hostname, $this->config);
break;
- case Cache\Cache::TYPE_APCU:
+ case Cache\Type::APCU:
$cache = new Cache\APCuCache($this->hostname);
break;
default:
namespace Friendica\Factory;
-use Friendica\Core\Cache\Cache;
use Friendica\Core\Cache\IMemoryCache;
+use Friendica\Core\Cache\Type;
use Friendica\Core\Config\IConfiguration;
use Friendica\Core\Lock;
use Friendica\Database\Database;
try {
switch ($lock_type) {
- case Cache::TYPE_MEMCACHE:
- case Cache::TYPE_MEMCACHED:
- case Cache::TYPE_REDIS:
- case Cache::TYPE_APCU:
+ case Type::MEMCACHE:
+ case Type::MEMCACHED:
+ case Type::REDIS:
+ case Type::APCU:
$cache = $this->cacheFactory->create($lock_type);
if ($cache instanceof IMemoryCache) {
return new Lock\CacheLock($cache);
// 2. Try to use Cache Locking (don't use the DB-Cache Locking because it works different!)
$cache_type = $this->config->get('system', 'cache_driver', 'database');
- if ($cache_type != Cache::TYPE_DATABASE) {
+ if ($cache_type != Type::DATABASE) {
try {
$cache = $this->cacheFactory->create($cache_type);
if ($cache instanceof IMemoryCache) {
namespace Friendica\Factory;
use Friendica\App;
-use Friendica\Core\Cache\Cache;
use Friendica\Core\Cache\ICache;
+use Friendica\Core\Cache\Type;
use Friendica\Core\Config\IConfiguration;
use Friendica\Core\Session;
use Friendica\Core\System;
break;
case self::HANDLER_CACHE:
// In case we're using the db as cache driver, use the native db session, not the cache
- if ($config->get('system', 'cache_driver') === Cache::TYPE_DATABASE) {
+ if ($config->get('system', 'cache_driver') === Type::DATABASE) {
$handler = new Session\Handler\Database($dba, $logger, $server);
} else {
$handler = new Session\Handler\Cache($cache, $logger, $server);
*/
namespace Friendica\Model;
-use Friendica\Core\Cache\Cache;
+use Friendica\Core\Cache\Duration;
use Friendica\Core\Config;
use Friendica\Core\L10n;
use Friendica\Core\Logger;
DBA::escape(L10n::t("Contact Photos"))
);
}
- DI::cache()->set($key, $albums, Cache::DAY);
+ DI::cache()->set($key, $albums, Duration::DAY);
}
return $albums;
}
public static function clearAlbumCache($uid)
{
$key = "photo_albums:".$uid.":".local_user().":".remote_user();
- DI::cache()->set($key, null, Cache::DAY);
+ DI::cache()->set($key, null, Duration::DAY);
}
/**
use Friendica\Content\Text\BBCode;
use Friendica\Content\Text\HTML;
use Friendica\Content\Widget\ContactBlock;
-use Friendica\Core\Cache\Cache;
+use Friendica\Core\Cache\Duration;
use Friendica\Core\Config;
use Friendica\Core\Hook;
use Friendica\Core\L10n;
);
if (DBA::isResult($s)) {
$r = DBA::toArray($s);
- DI::cache()->set($cachekey, $r, Cache::HOUR);
+ DI::cache()->set($cachekey, $r, Duration::HOUR);
}
}
Logger::log('URL ' . $my_url . ' already tried to authenticate.', Logger::DEBUG);
return;
} else {
- DI::cache()->set($cachekey, true, Cache::MINUTE);
+ DI::cache()->set($cachekey, true, Duration::MINUTE);
}
Logger::log('Not authenticated. Invoking reverse magic-auth for ' . $my_url, Logger::DEBUG);
*/
namespace Friendica\Model;
-use Friendica\Core\Cache\Cache;
+use Friendica\Core\Cache\Duration;
use Friendica\Core\Logger;
use Friendica\Database\DBA;
use Friendica\DI;
if (DBA::isResult($tagsStmt)) {
$tags = DBA::toArray($tagsStmt);
- DI::cache()->set('global_trending_tags', $tags, Cache::HOUR);
+ DI::cache()->set('global_trending_tags', $tags, Duration::HOUR);
}
}
if (DBA::isResult($tagsStmt)) {
$tags = DBA::toArray($tagsStmt);
- DI::cache()->set('local_trending_tags', $tags, Cache::HOUR);
+ DI::cache()->set('local_trending_tags', $tags, Duration::HOUR);
}
}
use Friendica\Content\Pager;
use Friendica\Content\Text\HTML;
use Friendica\Content\Widget;
-use Friendica\Core\Cache\Cache as CacheClass;
+use Friendica\Core\Cache\Duration;
use Friendica\Core\Config;
use Friendica\Core\L10n;
use Friendica\Core\Logger;
if (($resultdata->time > (time() - $crawl_permit_period)) && ($resultdata->accesses > $free_crawls)) {
throw new HTTPException\TooManyRequestsException(L10n::t('Only one search per minute is permitted for not logged in users.'));
}
- DI::cache()->set('remote_search:' . $remote, json_encode(['time' => time(), 'accesses' => $resultdata->accesses + 1]), CacheClass::HOUR);
+ DI::cache()->set('remote_search:' . $remote, json_encode(['time' => time(), 'accesses' => $resultdata->accesses + 1]), Duration::HOUR);
} else {
- DI::cache()->set('remote_search:' . $remote, json_encode(['time' => time(), 'accesses' => 1]), CacheClass::HOUR);
+ DI::cache()->set('remote_search:' . $remote, json_encode(['time' => time(), 'accesses' => 1]), Duration::HOUR);
}
}
use DOMDocument;
use DomXPath;
-use Friendica\Core\Cache\Cache;
+use Friendica\Core\Cache\Duration;
use Friendica\Core\Config;
use Friendica\Core\Logger;
use Friendica\Core\Protocol;
// Only store into the cache if the value seems to be valid
if (!in_array($data['network'], [Protocol::PHANTOM, Protocol::MAIL])) {
- DI::cache()->set('Probe::uri:' . $network . ':' . $uri, $data, Cache::DAY);
+ DI::cache()->set('Probe::uri:' . $network . ':' . $uri, $data, Duration::DAY);
}
return $data;
use Friendica\Content\Feature;
use Friendica\Content\Text\BBCode;
use Friendica\Content\Text\Plaintext;
-use Friendica\Core\Cache\Cache;
+use Friendica\Core\Cache\Duration;
use Friendica\Core\Config;
use Friendica\Core\Logger;
use Friendica\Core\Protocol;
$data = ActivityPub\Transmitter::createActivityFromItem($item_id);
- DI::cache()->set($cachekey, $data, Cache::QUARTER_HOUR);
+ DI::cache()->set($cachekey, $data, Duration::QUARTER_HOUR);
return $data;
}
use Friendica\Content\Feature;
use Friendica\Content\Text\BBCode;
use Friendica\Content\Text\Markdown;
-use Friendica\Core\Cache\Cache;
+use Friendica\Core\Cache\Duration;
use Friendica\Core\Config;
use Friendica\Core\L10n;
use Friendica\Core\Logger;
Logger::log("Send participation for ".$item["guid"]." by ".$author, Logger::DEBUG);
// It doesn't matter what we store, we only want to avoid sending repeated notifications for the same item
- DI::cache()->set($cachekey, $item["guid"], Cache::QUARTER_HOUR);
+ DI::cache()->set($cachekey, $item["guid"], Duration::QUARTER_HOUR);
return self::buildAndTransmit($owner, $contact, "participation", $message);
}
$msg = ["type" => $type, "message" => $message];
- DI::cache()->set($cachekey, $msg, Cache::QUARTER_HOUR);
+ DI::cache()->set($cachekey, $msg, Duration::QUARTER_HOUR);
return $msg;
}
$comment['thread_parent_guid'] = $thread_parent_item['guid'];
}
- DI::cache()->set($cachekey, $comment, Cache::QUARTER_HOUR);
+ DI::cache()->set($cachekey, $comment, Duration::QUARTER_HOUR);
return($comment);
}
use DOMXPath;
use Friendica\Content\Text\BBCode;
use Friendica\Content\Text\HTML;
-use Friendica\Core\Cache\Cache;
+use Friendica\Core\Cache\Duration;
use Friendica\Core\Config;
use Friendica\Core\L10n;
-use Friendica\Core\Lock;
use Friendica\Core\Logger;
use Friendica\Core\PConfig;
use Friendica\Core\Protocol;
$feeddata = trim($doc->saveXML());
$msg = ['feed' => $feeddata, 'last_update' => $last_update];
- DI::cache()->set($cachekey, $msg, Cache::QUARTER_HOUR);
+ DI::cache()->set($cachekey, $msg, Duration::QUARTER_HOUR);
Logger::log('Feed duration: ' . number_format(microtime(true) - $stamp, 3) . ' - ' . $owner_nick . ' - ' . $filter . ' - ' . $previous_created, Logger::DEBUG);
*/
namespace Friendica\Util;
-use Friendica\Core\Cache\Cache;
+use Friendica\Core\Cache\Duration;
use Friendica\Core\Logger;
use Exception;
use Friendica\DI;
}
$data = jsonld_default_document_loader($url);
- DI::cache()->set('documentLoader:' . $url, $data, Cache::DAY);
+ DI::cache()->set('documentLoader:' . $url, $data, Duration::DAY);
return $data;
}
*/
namespace Friendica\Worker;
-use Friendica\Core\Cache\Cache;
+use Friendica\Core\Cache\Duration;
use Friendica\Core\Config;
use Friendica\Core\Logger;
use Friendica\Core\Protocol;
}
}
}
- DI::cache()->set('SearchDirectory:' . $search, time(), Cache::DAY);
+ DI::cache()->set('SearchDirectory:' . $search, time(), Duration::DAY);
}
}
namespace Friendica\Test\Util;
-use Friendica\Core\Cache\Cache;
+use Friendica\Core\Cache\Duration;
use Friendica\Core\Lock\DatabaseLock;
trait DbaLockMockTrait
*@see DatabaseLock::acquire()
*
*/
- public function mockAcquireLock($key, $ttl = Cache::FIVE_MINUTES, $locked = false, $pid = null, $rowExists = true, $time = null, $times = null)
+ public function mockAcquireLock($key, $ttl = Duration::FIVE_MINUTES, $locked = false, $pid = null, $rowExists = true, $time = null, $times = null)
{
if ($time === null) {
$time = time();