add perfomance chapters
This commit is contained in:
parent
7a0f368e00
commit
3dd9f5a1d9
101 changed files with 8014 additions and 62 deletions
21
implementation/18-caching/src/Service/Cache/ApcuCache.php
Normal file
21
implementation/18-caching/src/Service/Cache/ApcuCache.php
Normal file
|
@ -0,0 +1,21 @@
|
|||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Lubian\NoFramework\Service\Cache;
|
||||
|
||||
use function apcu_add;
|
||||
use function apcu_fetch;
|
||||
|
||||
final class ApcuCache implements EasyCache
|
||||
{
|
||||
public function get(string $key, callable $callback, int $ttl = 0): mixed
|
||||
{
|
||||
$success = false;
|
||||
$result = apcu_fetch($key, $success);
|
||||
if ($success === true) {
|
||||
return $result;
|
||||
}
|
||||
$result = $callback();
|
||||
apcu_add($key, $result, $ttl);
|
||||
return $result;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue