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=1683629235; bh=avcnLkF+KUSG2udd+XktghHH57fNqNFGE1F1exRRWQ8=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=DdWBpmpTVG0yRyfyWjeiOn31rglttiSliEcGG3ZSPbViAJxwl8g4SItaRLF/ImNyQ j9XW5VonvwsAgAvYNQ3o3lzNp6HzE3V1Cc+MhNI25nwHXv4IPmknplf7hitDa4elDS RyPLovNbYjUtfkxvRb6qNiW+4rQMywGBLfrST2dHcAHTA/gkCYZ6UiSSoSOdQUvplL icEfPXnFUR9+6ioFmg6q3rM7ycWhbZa5cTUUzEILNrP29cPjUYRM/G5dqe1AX+SeGB 0TFgAOKra+NTrTfryFm+Ncgf6U4KJ1tt3YUq1h4AD9QbUAL29wx68xx/n7Jnwq2nmj YBusTRhdRNpXg== Received: from localhost.localdomain (unknown [128.199.192.202]) by gnuweeb.org (Postfix) with ESMTPSA id 07EC0245BC9; Tue, 9 May 2023 17:47:13 +0700 (WIB) From: Ammar Faizi To: GNU/Weeb FB Team Cc: Ammar Faizi , GNU/Weeb Mailing List , Michael William Jonathan Subject: [PATCH fb v1 4/6] fb: Post: Implement cache in `getTimelinePosts()` Date: Tue, 9 May 2023 17:46:56 +0700 Message-Id: <20230509104658.70953-5-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 | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/Facebook/Methods/Post.php b/src/Facebook/Methods/Post.php index 3cf5d7e9896e74ce..7fe38c5c1b982c72 100644 --- a/src/Facebook/Methods/Post.php +++ b/src/Facebook/Methods/Post.php @@ -96,6 +96,12 @@ trait Post */ public function getTimelinePosts(string $username, int $year = -1, bool $take_content = false, int $limit = -1): array { + $cacheKey = __METHOD__.$username.$year.($take_content ? 1 : 0).sprintf("%010d", $limit); + + $posts = $this->getCache($cacheKey); + if (is_array($posts)) + return $posts; + $years = $this->getTimelineYears($username); if ($year === -1) { $year = max(array_keys($years)); @@ -155,6 +161,7 @@ trait Post ]; } + $this->setCache($cacheKey, $posts); return $posts; } -- Ammar Faizi