Added apcu caching method and bump

This commit is contained in:
Pablo Ferreiro 2023-01-25 15:56:23 +01:00
parent faf1dcee51
commit d273b35e53
No known key found for this signature in database
GPG key ID: 41FBCE65B779FA24
5 changed files with 38 additions and 8 deletions

25
app/Cache/ApcuCache.php Normal file
View file

@ -0,0 +1,25 @@
<?php
namespace App\Cache;
use TikScraper\Interfaces\CacheInterface;
class ApcuCache implements CacheInterface {
function __construct() {
if (!(extension_loaded('apcu') && apcu_enabled())) {
throw new \Exception('APCu not enabled');
}
}
public function get(string $cache_key): ?object {
$data = apcu_fetch($cache_key);
return $data !== false ? json_decode($data) : null;
}
public function exists(string $cache_key): bool {
return apcu_exists($cache_key);
}
public function set(string $cache_key, string $data, $timeout = 3600): void {
apcu_store($cache_key, $data, $timeout);
}
}