diff --git a/mod/ping.php b/mod/ping.php index c76780f69..26d0efb37 100644 --- a/mod/ping.php +++ b/mod/ping.php @@ -6,7 +6,7 @@ use Friendica\App; use Friendica\Content\ForumManager; use Friendica\Content\Text\BBCode; -use Friendica\Core\Cache; +use Friendica\Core\Cache\Cache; use Friendica\Core\Config; use Friendica\Core\Hook; use Friendica\Core\L10n; @@ -197,7 +197,7 @@ function ping_init(App $a) } $cachekey = "ping_init:".local_user(); - $ev = Cache::get($cachekey); + $ev = DI::cache()->get($cachekey); if (is_null($ev)) { $ev = q( "SELECT type, start, adjust FROM `event` @@ -208,7 +208,7 @@ function ping_init(App $a) DBA::escape(DateTimeFormat::utcNow()) ); if (DBA::isResult($ev)) { - Cache::set($cachekey, $ev, Cache::HOUR); + DI::cache()->set($cachekey, $ev, Cache::HOUR); } } diff --git a/mod/poco.php b/mod/poco.php index 2ed871285..595a4bd2e 100644 --- a/mod/poco.php +++ b/mod/poco.php @@ -6,13 +6,12 @@ use Friendica\App; use Friendica\Content\Text\BBCode; -use Friendica\Core\Cache; use Friendica\Core\Config; use Friendica\Core\Logger; use Friendica\Core\Protocol; use Friendica\Core\Renderer; -use Friendica\Core\System; use Friendica\Database\DBA; +use Friendica\DI; use Friendica\Protocol\PortableContact; use Friendica\Util\DateTimeFormat; use Friendica\Util\Strings; @@ -255,10 +254,10 @@ function poco_init(App $a) { if (isset($contact['account-type'])) { $contact['contact-type'] = $contact['account-type']; } - $about = Cache::get("about:" . $contact['updated'] . ":" . $contact['nurl']); + $about = DI::cache()->get("about:" . $contact['updated'] . ":" . $contact['nurl']); if (is_null($about)) { $about = BBCode::convert($contact['about'], false); - Cache::set("about:" . $contact['updated'] . ":" . $contact['nurl'], $about); + DI::cache()->set("about:" . $contact['updated'] . ":" . $contact['nurl'], $about); } // Non connected persons can only see the keywords of a Diaspora account diff --git a/src/Content/OEmbed.php b/src/Content/OEmbed.php index 95fd6530b..4bcb485fc 100644 --- a/src/Content/OEmbed.php +++ b/src/Content/OEmbed.php @@ -10,7 +10,7 @@ use DOMNode; use DOMText; use DOMXPath; use Exception; -use Friendica\Core\Cache; +use Friendica\Core\Cache\Cache; use Friendica\Core\Config; use Friendica\Core\Hook; use Friendica\Core\L10n; @@ -66,7 +66,7 @@ class OEmbed if (DBA::isResult($oembed_record)) { $json_string = $oembed_record['content']; } else { - $json_string = Cache::get($cache_key); + $json_string = DI::cache()->get($cache_key); } // These media files should now be caught in bbcode.php @@ -125,7 +125,7 @@ class OEmbed $cache_ttl = Cache::FIVE_MINUTES; } - Cache::set($cache_key, $json_string, $cache_ttl); + DI::cache()->set($cache_key, $json_string, $cache_ttl); } if ($oembed->type == 'error') { diff --git a/src/Content/Text/BBCode.php b/src/Content/Text/BBCode.php index 51fa08ad3..19ff88a9c 100644 --- a/src/Content/Text/BBCode.php +++ b/src/Content/Text/BBCode.php @@ -10,7 +10,6 @@ use DOMXPath; use Exception; use Friendica\Content\OEmbed; use Friendica\Content\Smilies; -use Friendica\Core\Cache; use Friendica\Core\Config; use Friendica\Core\Hook; use Friendica\Core\L10n; @@ -1070,7 +1069,7 @@ class BBCode private static function removePictureLinksCallback($match) { $cache_key = 'remove:' . $match[1]; - $text = Cache::get($cache_key); + $text = DI::cache()->get($cache_key); if (is_null($text)) { $a = DI::app(); @@ -1112,7 +1111,7 @@ class BBCode } } } - Cache::set($cache_key, $text); + DI::cache()->set($cache_key, $text); } return $text; @@ -1143,7 +1142,7 @@ class BBCode } $cache_key = 'clean:' . $match[1]; - $text = Cache::get($cache_key); + $text = DI::cache()->get($cache_key); if (!is_null($text)) { return $text; } @@ -1194,7 +1193,7 @@ class BBCode } } } - Cache::set($cache_key, $text); + DI::cache()->set($cache_key, $text); return $text; } diff --git a/src/Content/Widget/TrendingTags.php b/src/Content/Widget/TrendingTags.php index a7cfa8557..4ac8a1119 100644 --- a/src/Content/Widget/TrendingTags.php +++ b/src/Content/Widget/TrendingTags.php @@ -2,10 +2,8 @@ namespace Friendica\Content\Widget; -use Friendica\Core\Cache; use Friendica\Core\L10n; use Friendica\Core\Renderer; -use Friendica\Database\DBA; use Friendica\Model\Term; /** diff --git a/src/Core/Cache.php b/src/Core/Cache.php deleted file mode 100644 index d0a04b9ec..000000000 --- a/src/Core/Cache.php +++ /dev/null @@ -1,102 +0,0 @@ -getAllKeys($prefix); - } - - /** - * @brief Fetch cached data according to the key - * - * @param string $key The key to the cached data - * - * @return mixed Cached $value or "null" if not found - * @throws \Exception - */ - public static function get($key) - { - return DI::cache()->get($key); - } - - /** - * @brief Put data in the cache according to the key - * - * The input $value can have multiple formats. - * - * @param string $key The key to the cached data - * @param mixed $value The value that is about to be stored - * @param integer $duration The cache lifespan - * - * @return bool - * @throws \Exception - */ - public static function set($key, $value, $duration = CacheClass::MONTH) - { - return DI::cache()->set($key, $value, $duration); - } - - /** - * @brief Delete a value from the cache - * - * @param string $key The key to the cached data - * - * @return bool - * @throws \Exception - */ - public static function delete($key) - { - return DI::cache()->delete($key); - } - - /** - * @brief Remove outdated data from the cache - * - * @param boolean $outdated just remove outdated values - * - * @return bool - * @throws \Exception - */ - public static function clear($outdated = true) - { - return DI::cache()->clear($outdated); - } -} diff --git a/src/Core/Lock/DatabaseLock.php b/src/Core/Lock/DatabaseLock.php index 0788f04b2..eeb488fba 100644 --- a/src/Core/Lock/DatabaseLock.php +++ b/src/Core/Lock/DatabaseLock.php @@ -2,7 +2,7 @@ namespace Friendica\Core\Lock; -use Friendica\Core\Cache; +use Friendica\Core\Cache\Cache; use Friendica\Database\Database; use Friendica\Util\DateTimeFormat; diff --git a/src/Core/Update.php b/src/Core/Update.php index badbdc785..62ea573db 100644 --- a/src/Core/Update.php +++ b/src/Core/Update.php @@ -7,6 +7,7 @@ use Friendica\Database\DBA; use Friendica\Database\DBStructure; use Friendica\DI; use Friendica\Util\Strings; +use Friendica\Core\Cache\Cache; class Update { diff --git a/src/Model/Photo.php b/src/Model/Photo.php index 9e2671140..4f6b1640d 100644 --- a/src/Model/Photo.php +++ b/src/Model/Photo.php @@ -6,7 +6,7 @@ */ namespace Friendica\Model; -use Friendica\Core\Cache; +use Friendica\Core\Cache\Cache; use Friendica\Core\Config; use Friendica\Core\L10n; use Friendica\Core\Logger; @@ -540,7 +540,7 @@ class Photo $sql_extra = Security::getPermissionsSQLByUserId($uid); $key = "photo_albums:".$uid.":".local_user().":".remote_user(); - $albums = Cache::get($key); + $albums = DI::cache()->get($key); if (is_null($albums) || $update) { if (!Config::get("system", "no_count", false)) { /// @todo This query needs to be renewed. It is really slow @@ -563,7 +563,7 @@ class Photo DBA::escape(L10n::t("Contact Photos")) ); } - Cache::set($key, $albums, Cache::DAY); + DI::cache()->set($key, $albums, Cache::DAY); } return $albums; } @@ -576,7 +576,7 @@ class Photo public static function clearAlbumCache($uid) { $key = "photo_albums:".$uid.":".local_user().":".remote_user(); - Cache::set($key, null, Cache::DAY); + DI::cache()->set($key, null, Cache::DAY); } /** diff --git a/src/Model/Profile.php b/src/Model/Profile.php index d7cc906fd..bf6da81cb 100644 --- a/src/Model/Profile.php +++ b/src/Model/Profile.php @@ -10,7 +10,7 @@ use Friendica\Content\ForumManager; use Friendica\Content\Text\BBCode; use Friendica\Content\Text\HTML; use Friendica\Content\Widget\ContactBlock; -use Friendica\Core\Cache; +use Friendica\Core\Cache\Cache; use Friendica\Core\Config; use Friendica\Core\Hook; use Friendica\Core\L10n; @@ -586,7 +586,7 @@ class Profile $bd_short = L10n::t('F d'); $cachekey = 'get_birthdays:' . local_user(); - $r = Cache::get($cachekey); + $r = DI::cache()->get($cachekey); if (is_null($r)) { $s = DBA::p( "SELECT `event`.*, `event`.`id` AS `eid`, `contact`.* FROM `event` @@ -608,7 +608,7 @@ class Profile ); if (DBA::isResult($s)) { $r = DBA::toArray($s); - Cache::set($cachekey, $r, Cache::HOUR); + DI::cache()->set($cachekey, $r, Cache::HOUR); } } @@ -1066,11 +1066,11 @@ class Profile // Avoid endless loops $cachekey = 'zrlInit:' . $my_url; - if (Cache::get($cachekey)) { + if (DI::cache()->get($cachekey)) { Logger::log('URL ' . $my_url . ' already tried to authenticate.', Logger::DEBUG); return; } else { - Cache::set($cachekey, true, Cache::MINUTE); + DI::cache()->set($cachekey, true, Cache::MINUTE); } Logger::log('Not authenticated. Invoking reverse magic-auth for ' . $my_url, Logger::DEBUG); diff --git a/src/Model/Term.php b/src/Model/Term.php index 08a02ff07..2f8da0fac 100644 --- a/src/Model/Term.php +++ b/src/Model/Term.php @@ -4,7 +4,7 @@ */ namespace Friendica\Model; -use Friendica\Core\Cache; +use Friendica\Core\Cache\Cache; use Friendica\Core\Logger; use Friendica\Database\DBA; use Friendica\DI; @@ -57,7 +57,7 @@ class Term */ public static function getGlobalTrendingHashtags(int $period, $limit = 10) { - $tags = Cache::get('global_trending_tags'); + $tags = DI::cache()->get('global_trending_tags'); if (!$tags) { $tagsStmt = DBA::p("SELECT t.`term`, COUNT(*) AS `score` @@ -84,7 +84,7 @@ class Term if (DBA::isResult($tagsStmt)) { $tags = DBA::toArray($tagsStmt); - Cache::set('global_trending_tags', $tags, Cache::HOUR); + DI::cache()->set('global_trending_tags', $tags, Cache::HOUR); } } @@ -100,7 +100,7 @@ class Term */ public static function getLocalTrendingHashtags(int $period, $limit = 10) { - $tags = Cache::get('local_trending_tags'); + $tags = DI::cache()->get('local_trending_tags'); if (!$tags) { $tagsStmt = DBA::p("SELECT t.`term`, COUNT(*) AS `score` @@ -129,7 +129,7 @@ class Term if (DBA::isResult($tagsStmt)) { $tags = DBA::toArray($tagsStmt); - Cache::set('local_trending_tags', $tags, Cache::HOUR); + DI::cache()->set('local_trending_tags', $tags, Cache::HOUR); } } diff --git a/src/Module/Search/Index.php b/src/Module/Search/Index.php index 247ac5988..995fb85d1 100644 --- a/src/Module/Search/Index.php +++ b/src/Module/Search/Index.php @@ -2,13 +2,10 @@ namespace Friendica\Module\Search; -use Friendica\App\Arguments; -use Friendica\App\BaseURL; use Friendica\Content\Nav; use Friendica\Content\Pager; use Friendica\Content\Text\HTML; use Friendica\Content\Widget; -use Friendica\Core\Cache; use Friendica\Core\Cache\Cache as CacheClass; use Friendica\Core\Config; use Friendica\Core\L10n; @@ -53,15 +50,15 @@ class Index extends BaseSearchModule $crawl_permit_period = 10; $remote = $_SERVER['REMOTE_ADDR']; - $result = Cache::get('remote_search:' . $remote); + $result = DI::cache()->get('remote_search:' . $remote); if (!is_null($result)) { $resultdata = json_decode($result); 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.')); } - 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]), CacheClass::HOUR); } else { - 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]), CacheClass::HOUR); } } diff --git a/src/Network/Probe.php b/src/Network/Probe.php index 122df70ce..497fd3c51 100644 --- a/src/Network/Probe.php +++ b/src/Network/Probe.php @@ -11,7 +11,7 @@ namespace Friendica\Network; use DOMDocument; use DomXPath; -use Friendica\Core\Cache; +use Friendica\Core\Cache\Cache; use Friendica\Core\Config; use Friendica\Core\Logger; use Friendica\Core\Protocol; @@ -332,7 +332,7 @@ class Probe public static function uri($uri, $network = '', $uid = -1, $cache = true) { if ($cache) { - $result = Cache::get('Probe::uri:' . $network . ':' . $uri); + $result = DI::cache()->get('Probe::uri:' . $network . ':' . $uri); if (!is_null($result)) { return $result; } @@ -409,7 +409,7 @@ class Probe // Only store into the cache if the value seems to be valid if (!in_array($data['network'], [Protocol::PHANTOM, Protocol::MAIL])) { - Cache::set('Probe::uri:' . $network . ':' . $uri, $data, Cache::DAY); + DI::cache()->set('Probe::uri:' . $network . ':' . $uri, $data, Cache::DAY); } return $data; diff --git a/src/Protocol/ActivityPub/Transmitter.php b/src/Protocol/ActivityPub/Transmitter.php index 6a512323c..dbfd67cb0 100644 --- a/src/Protocol/ActivityPub/Transmitter.php +++ b/src/Protocol/ActivityPub/Transmitter.php @@ -7,7 +7,7 @@ namespace Friendica\Protocol\ActivityPub; use Friendica\Content\Feature; use Friendica\Content\Text\BBCode; use Friendica\Content\Text\Plaintext; -use Friendica\Core\Cache; +use Friendica\Core\Cache\Cache; use Friendica\Core\Config; use Friendica\Core\Logger; use Friendica\Core\Protocol; @@ -819,7 +819,7 @@ class Transmitter $cachekey = 'APDelivery:createActivity:' . $item_id; if (!$force) { - $data = Cache::get($cachekey); + $data = DI::cache()->get($cachekey); if (!is_null($data)) { return $data; } @@ -827,7 +827,7 @@ class Transmitter $data = ActivityPub\Transmitter::createActivityFromItem($item_id); - Cache::set($cachekey, $data, Cache::QUARTER_HOUR); + DI::cache()->set($cachekey, $data, Cache::QUARTER_HOUR); return $data; } diff --git a/src/Protocol/Diaspora.php b/src/Protocol/Diaspora.php index a683a2351..b3e6956f5 100644 --- a/src/Protocol/Diaspora.php +++ b/src/Protocol/Diaspora.php @@ -13,7 +13,7 @@ namespace Friendica\Protocol; use Friendica\Content\Feature; use Friendica\Content\Text\BBCode; use Friendica\Content\Text\Markdown; -use Friendica\Core\Cache; +use Friendica\Core\Cache\Cache; use Friendica\Core\Config; use Friendica\Core\L10n; use Friendica\Core\Logger; @@ -3246,7 +3246,7 @@ class Diaspora $cachekey = "diaspora:sendParticipation:".$item['guid']; - $result = Cache::get($cachekey); + $result = DI::cache()->get($cachekey); if (!is_null($result)) { return; } @@ -3272,7 +3272,7 @@ class Diaspora 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 - Cache::set($cachekey, $item["guid"], Cache::QUARTER_HOUR); + DI::cache()->set($cachekey, $item["guid"], Cache::QUARTER_HOUR); return self::buildAndTransmit($owner, $contact, "participation", $message); } @@ -3524,7 +3524,7 @@ class Diaspora { $cachekey = "diaspora:buildStatus:".$item['guid']; - $result = Cache::get($cachekey); + $result = DI::cache()->get($cachekey); if (!is_null($result)) { return $result; } @@ -3628,7 +3628,7 @@ class Diaspora $msg = ["type" => $type, "message" => $message]; - Cache::set($cachekey, $msg, Cache::QUARTER_HOUR); + DI::cache()->set($cachekey, $msg, Cache::QUARTER_HOUR); return $msg; } @@ -3749,7 +3749,7 @@ class Diaspora { $cachekey = "diaspora:constructComment:".$item['guid']; - $result = Cache::get($cachekey); + $result = DI::cache()->get($cachekey); if (!is_null($result)) { return $result; } @@ -3798,7 +3798,7 @@ class Diaspora $comment['thread_parent_guid'] = $thread_parent_item['guid']; } - Cache::set($cachekey, $comment, Cache::QUARTER_HOUR); + DI::cache()->set($cachekey, $comment, Cache::QUARTER_HOUR); return($comment); } diff --git a/src/Protocol/OStatus.php b/src/Protocol/OStatus.php index 2e47f18d1..0eec477a6 100644 --- a/src/Protocol/OStatus.php +++ b/src/Protocol/OStatus.php @@ -8,7 +8,7 @@ use DOMDocument; use DOMXPath; use Friendica\Content\Text\BBCode; use Friendica\Content\Text\HTML; -use Friendica\Core\Cache; +use Friendica\Core\Cache\Cache; use Friendica\Core\Config; use Friendica\Core\L10n; use Friendica\Core\Lock; @@ -2185,7 +2185,7 @@ class OStatus // Don't cache when the last item was posted less then 15 minutes ago (Cache duration) if ((time() - strtotime($owner['last-item'])) < 15*60) { - $result = Cache::get($cachekey); + $result = DI::cache()->get($cachekey); if (!$nocache && !is_null($result)) { Logger::log('Feed duration: ' . number_format(microtime(true) - $stamp, 3) . ' - ' . $owner_nick . ' - ' . $filter . ' - ' . $previous_created . ' (cached)', Logger::DEBUG); $last_update = $result['last_update']; @@ -2246,7 +2246,7 @@ class OStatus $feeddata = trim($doc->saveXML()); $msg = ['feed' => $feeddata, 'last_update' => $last_update]; - Cache::set($cachekey, $msg, Cache::QUARTER_HOUR); + DI::cache()->set($cachekey, $msg, Cache::QUARTER_HOUR); Logger::log('Feed duration: ' . number_format(microtime(true) - $stamp, 3) . ' - ' . $owner_nick . ' - ' . $filter . ' - ' . $previous_created, Logger::DEBUG); diff --git a/src/Util/Images.php b/src/Util/Images.php index e19304bba..e5a4da5b1 100644 --- a/src/Util/Images.php +++ b/src/Util/Images.php @@ -2,7 +2,6 @@ namespace Friendica\Util; -use Friendica\Core\Cache; use Friendica\Core\Logger; use Friendica\Core\System; use Friendica\DI; @@ -125,12 +124,12 @@ class Images return $data; } - $data = Cache::get($url); + $data = DI::cache()->get($url); if (empty($data) || !is_array($data)) { $data = self::getInfoFromURL($url); - Cache::set($url, $data); + DI::cache()->set($url, $data); } return $data; diff --git a/src/Util/JsonLD.php b/src/Util/JsonLD.php index 926fa1437..a56738ffb 100644 --- a/src/Util/JsonLD.php +++ b/src/Util/JsonLD.php @@ -4,9 +4,10 @@ */ namespace Friendica\Util; -use Friendica\Core\Cache; +use Friendica\Core\Cache\Cache; use Friendica\Core\Logger; use Exception; +use Friendica\DI; /** * @brief This class contain methods to work with JsonLD data @@ -39,13 +40,13 @@ class JsonLD exit(); } - $result = Cache::get('documentLoader:' . $url); + $result = DI::cache()->get('documentLoader:' . $url); if (!is_null($result)) { return $result; } $data = jsonld_default_document_loader($url); - Cache::set('documentLoader:' . $url, $data, Cache::DAY); + DI::cache()->set('documentLoader:' . $url, $data, Cache::DAY); return $data; } diff --git a/src/Worker/CronJobs.php b/src/Worker/CronJobs.php index 6a8d65464..e423fa28b 100644 --- a/src/Worker/CronJobs.php +++ b/src/Worker/CronJobs.php @@ -5,7 +5,6 @@ namespace Friendica\Worker; use Friendica\App; -use Friendica\Core\Cache; use Friendica\Core\Config; use Friendica\Core\Logger; use Friendica\Core\Protocol; @@ -154,7 +153,7 @@ class CronJobs } // clear old cache - Cache::clear(); + DI::cache()->clear(); // clear old item cache files clear_cache(); diff --git a/src/Worker/SearchDirectory.php b/src/Worker/SearchDirectory.php index 4503f21ca..3975fe1f7 100644 --- a/src/Worker/SearchDirectory.php +++ b/src/Worker/SearchDirectory.php @@ -4,12 +4,13 @@ */ namespace Friendica\Worker; -use Friendica\Core\Cache; +use Friendica\Core\Cache\Cache; use Friendica\Core\Config; use Friendica\Core\Logger; use Friendica\Core\Protocol; use Friendica\Core\Search; use Friendica\Database\DBA; +use Friendica\DI; use Friendica\Model\GContact; use Friendica\Model\GServer; use Friendica\Network\Probe; @@ -26,7 +27,7 @@ class SearchDirectory return; } - $data = Cache::get('SearchDirectory:' . $search); + $data = DI::cache()->get('SearchDirectory:' . $search); if (!is_null($data)) { // Only search for the same item every 24 hours if (time() < $data + (60 * 60 * 24)) { @@ -80,6 +81,6 @@ class SearchDirectory } } } - Cache::set('SearchDirectory:' . $search, time(), Cache::DAY); + DI::cache()->set('SearchDirectory:' . $search, time(), Cache::DAY); } } diff --git a/tests/Util/DbaLockMockTrait.php b/tests/Util/DbaLockMockTrait.php index 09bfd130c..b7b9fb91d 100644 --- a/tests/Util/DbaLockMockTrait.php +++ b/tests/Util/DbaLockMockTrait.php @@ -2,7 +2,7 @@ namespace Friendica\Test\Util; -use Friendica\Core\Cache; +use Friendica\Core\Cache\Cache; use Friendica\Core\Lock\DatabaseLock; trait DbaLockMockTrait