From f68929633b4eb04290381d269e80856fb65c4c5f Mon Sep 17 00:00:00 2001 From: nupplaPhil Date: Tue, 7 Jan 2020 00:41:20 +0100 Subject: [PATCH] Move Cache::set() to DI::cache()->set() --- mod/ping.php | 2 +- mod/poco.php | 3 ++- src/Content/OEmbed.php | 2 +- src/Content/Text/BBCode.php | 4 ++-- src/Core/Cache.php | 17 ----------------- src/Model/Photo.php | 4 ++-- src/Model/Profile.php | 4 ++-- src/Model/Term.php | 4 ++-- src/Module/Search/Index.php | 4 ++-- src/Network/Probe.php | 2 +- src/Protocol/ActivityPub/Transmitter.php | 2 +- src/Protocol/Diaspora.php | 6 +++--- src/Protocol/OStatus.php | 2 +- src/Util/Images.php | 2 +- src/Util/JsonLD.php | 3 ++- src/Worker/SearchDirectory.php | 3 ++- 16 files changed, 25 insertions(+), 39 deletions(-) diff --git a/mod/ping.php b/mod/ping.php index c76780f69..9593d6ed2 100644 --- a/mod/ping.php +++ b/mod/ping.php @@ -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..cbee26458 100644 --- a/mod/poco.php +++ b/mod/poco.php @@ -13,6 +13,7 @@ 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; @@ -258,7 +259,7 @@ function poco_init(App $a) { $about = 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..51918283e 100644 --- a/src/Content/OEmbed.php +++ b/src/Content/OEmbed.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..1489ed232 100644 --- a/src/Content/Text/BBCode.php +++ b/src/Content/Text/BBCode.php @@ -1112,7 +1112,7 @@ class BBCode } } } - Cache::set($cache_key, $text); + DI::cache()->set($cache_key, $text); } return $text; @@ -1194,7 +1194,7 @@ class BBCode } } } - Cache::set($cache_key, $text); + DI::cache()->set($cache_key, $text); return $text; } diff --git a/src/Core/Cache.php b/src/Core/Cache.php index 0328cf84c..410f9fea1 100644 --- a/src/Core/Cache.php +++ b/src/Core/Cache.php @@ -43,21 +43,4 @@ class Cache { 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); - } } diff --git a/src/Model/Photo.php b/src/Model/Photo.php index c4dbf2b30..0d05d81d0 100644 --- a/src/Model/Photo.php +++ b/src/Model/Photo.php @@ -569,7 +569,7 @@ class Photo DBA::escape(L10n::t("Contact Photos")) ); } - Cache::set($key, $albums, Cache::DAY); + DI::cache()->set($key, $albums, Cache::DAY); } return $albums; } @@ -582,7 +582,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..a5619c999 100644 --- a/src/Model/Profile.php +++ b/src/Model/Profile.php @@ -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); } } @@ -1070,7 +1070,7 @@ class Profile 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..4eca9639f 100644 --- a/src/Model/Term.php +++ b/src/Model/Term.php @@ -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); } } @@ -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..776b3fced 100644 --- a/src/Module/Search/Index.php +++ b/src/Module/Search/Index.php @@ -59,9 +59,9 @@ class Index extends BaseSearchModule 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..c3279cd9d 100644 --- a/src/Network/Probe.php +++ b/src/Network/Probe.php @@ -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..9a2b584fe 100644 --- a/src/Protocol/ActivityPub/Transmitter.php +++ b/src/Protocol/ActivityPub/Transmitter.php @@ -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..2d94e96c2 100644 --- a/src/Protocol/Diaspora.php +++ b/src/Protocol/Diaspora.php @@ -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); } @@ -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; } @@ -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 21659a603..38936762e 100644 --- a/src/Protocol/OStatus.php +++ b/src/Protocol/OStatus.php @@ -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..b557d891d 100644 --- a/src/Util/Images.php +++ b/src/Util/Images.php @@ -130,7 +130,7 @@ class Images 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..598898c0e 100644 --- a/src/Util/JsonLD.php +++ b/src/Util/JsonLD.php @@ -7,6 +7,7 @@ namespace Friendica\Util; use Friendica\Core\Cache; use Friendica\Core\Logger; use Exception; +use Friendica\DI; /** * @brief This class contain methods to work with JsonLD data @@ -45,7 +46,7 @@ class JsonLD } $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/SearchDirectory.php b/src/Worker/SearchDirectory.php index 4503f21ca..fcac721df 100644 --- a/src/Worker/SearchDirectory.php +++ b/src/Worker/SearchDirectory.php @@ -10,6 +10,7 @@ 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; @@ -80,6 +81,6 @@ class SearchDirectory } } } - Cache::set('SearchDirectory:' . $search, time(), Cache::DAY); + DI::cache()->set('SearchDirectory:' . $search, time(), Cache::DAY); } }