From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on gnuweeb.org X-Spam-Level: X-Spam-Status: No, score=-1.2 required=5.0 tests=ALL_TRUSTED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1683629233; bh=n9X/Bh8TDB4tCPQkTnz84MII15vd4M6auRwxlalTzRw=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=bItFKFTDO4Av0C8lPay4LFYLVQbbnhrqQ4BPBunlDRMfu/T6Iz901zPpkcZUBwgJ2 ARako9RLkLQ/5TQjetJZFGp/12a87kWgzoBjFlNobMIv8mlyffZn9NCzRbH7DQgC+T 9PJ54XkMNKWf9XPm44sg7xrcIbaQF+oixlfpbmQeOh2xmyqXf/o3EtbER3Irbh8FNK u+SlGSC9xjpkp1S9BGuRJeN36kW1VkDhf1pI245G4bfHicUrKzu7DZbHYzQsp3oZp7 YZ/Rjxz7gxrKSw9QQYOITz9KzkP26ZifgF/vZVaxxtViieNrje4xfzWGIQDhDbh5nV zdjwLgJbsmwmA== Received: from localhost.localdomain (unknown [128.199.192.202]) by gnuweeb.org (Postfix) with ESMTPSA id C2EF0245C71; Tue, 9 May 2023 17:47:11 +0700 (WIB) From: Ammar Faizi To: GNU/Weeb FB Team Cc: Ammar Faizi , GNU/Weeb Mailing List , Michael William Jonathan Subject: [PATCH fb v1 3/6] fb: Post: Implement cache in `getPost()` Date: Tue, 9 May 2023 17:46:55 +0700 Message-Id: <20230509104658.70953-4-ammarfaizi2@gnuweeb.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230509104658.70953-1-ammarfaizi2@gnuweeb.org> References: <20230509104658.70953-1-ammarfaizi2@gnuweeb.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: Make short repeated calls fast. Signed-off-by: Ammar Faizi --- src/Facebook/Methods/Post.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Facebook/Methods/Post.php b/src/Facebook/Methods/Post.php index 81017c9122e6c341..3cf5d7e9896e74ce 100644 --- a/src/Facebook/Methods/Post.php +++ b/src/Facebook/Methods/Post.php @@ -353,6 +353,13 @@ trait Post */ public function getPost(string $post_id): array { + $cacheKey = __METHOD__.$post_id; + + $ret = $this->getCache($cacheKey); + if ($ret) { + return $ret; + } + /** * $post_id must be numeric or a string starts with "pfbid". */ @@ -372,9 +379,11 @@ trait Post $content = $this->parsePostContent($o); $content["embedded_link"] = $this->parseEmbeddedLink($orig); - return [ + $ret = [ "content" => $content, "info" => $info ]; + $this->setCache($cacheKey, $ret); + return $ret; } } -- Ammar Faizi