From 6715a036e9c605ef7d870a5bdefb2659b8772ef4 Mon Sep 17 00:00:00 2001 From: Hugo Sales Date: Mon, 20 Sep 2021 16:13:12 +0100 Subject: [PATCH] [CACHE] Add way to fetch limit,offset values from a list --- src/Core/Cache.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Core/Cache.php b/src/Core/Cache.php index b3bc86c20c..f63e222ae8 100644 --- a/src/Core/Cache.php +++ b/src/Core/Cache.php @@ -146,7 +146,7 @@ abstract class Cache * Retrieve a list from the cache, with a different implementation * for redis and others, trimming to $max_count if given */ - public static function getList(string $key, callable $calculate, string $pool = 'default', ?int $max_count = null, float $beta = 1.0): array + public static function getList(string $key, callable $calculate, string $pool = 'default', ?int $max_count = null, ?int $offset = null, ?int $limit = null, float $beta = 1.0): array { if (isset(self::$redis[$pool])) { if (!($recompute = $beta === INF || !(self::$redis[$pool]->exists($key)))) { @@ -169,10 +169,10 @@ abstract class Cache $res = $calculate(null, $save); if ($save) { self::setList($key, $res, $pool, $max_count, $beta); - return $res; + return array_slice($res, $offset ?? 0, $limit); } } - return self::$redis[$pool]->lRange($key, 0, $max_count ?? -1); + return self::$redis[$pool]->lRange($key, $offset ?? 0, ($offset ?? 0) + ($limit ?? $max_count ?? -1)); } else { return self::get($key, function () use ($calculate, $max_count) { $res = $calculate(null);