Skip to content

Commit dae01c0

Browse files
authored
Merge pull request #30 from williamhuntjr/ABOAT-1480
ABOAT-1480 - User authentication for Neb 2
2 parents 6fe6df1 + 1952496 commit dae01c0

File tree

4 files changed

+10
-7
lines changed

4 files changed

+10
-7
lines changed

src/Memoize.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ interface Memoize
1010
* @param string $key The key to fetch
1111
* @param callable $compute A function to run if the value was not cached that will return the result.
1212
* @param int $cacheTime The number of seconds to cache the response for, or null to not expire it ever.
13+
* @param bool $refresh Determines if cache should be refreshed.
1314
*
1415
* @return mixed The data requested, optionally pulled from cache
1516
*/
16-
public function memoizeCallable(string $key, callable $compute, int $cacheTime = null);
17+
public function memoizeCallable(string $key, callable $compute, int $cacheTime = null, bool $refresh = false);
1718
}

src/Memory.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,13 @@ class Memory implements Memoize
2222
* @param string $key
2323
* @param callable $compute
2424
* @param int|null $cacheTime
25+
* @param bool $refresh
2526
*
2627
* @return mixed
2728
*/
28-
public function memoizeCallable(string $key, callable $compute, int $cacheTime = null)
29+
public function memoizeCallable(string $key, callable $compute, int $cacheTime = null, bool $refresh = false)
2930
{
30-
if (array_key_exists($key, $this->cache)) {
31+
if (array_key_exists($key, $this->cache) && !$refresh) {
3132
return $this->cache[$key];
3233
}
3334

src/None.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@ class None implements Memoize
1616
* @param string $key
1717
* @param callable $compute
1818
* @param int|null $cacheTime
19+
* @param bool $refresh
1920
*
2021
* @return mixed
2122
*/
22-
public function memoizeCallable(string $key, callable $compute, int $cacheTime = null)
23+
public function memoizeCallable(string $key, callable $compute, int $cacheTime = null, bool $refresh = false)
2324
{
2425
return call_user_func($compute);
2526
}

src/Predis.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,13 @@ public function __construct(
6565
* @param string $key
6666
* @param callable $compute
6767
* @param int|null $cacheTime
68+
* @param bool $refresh
6869
*
6970
* @return mixed
7071
*/
71-
public function memoizeCallable(string $key, callable $compute, int $cacheTime = null)
72+
public function memoizeCallable(string $key, callable $compute, int $cacheTime = null, bool $refresh = false)
7273
{
73-
if (!$this->refresh) {
74+
if (!$this->refresh && !$refresh) {
7475
try {
7576
if (rand(1, 100) <= $this->refreshPercent) {
7677
// {$refreshPercent}% of requests should check to see if this key is almost expired.
@@ -82,7 +83,6 @@ public function memoizeCallable(string $key, callable $compute, int $cacheTime =
8283
return $this->getData($key, $compute, $cacheTime);
8384
}
8485
}
85-
8686
$cached = $this->client->get($key);
8787
if ($cached !== null) {
8888
$data = json_decode($cached, true);

0 commit comments

Comments
 (0)