Skip to content

Commit f6db0b0

Browse files
authored
Use apcu instead of laravel cache (#32)
* Use apcu instead of laravel cache * Cs fix
1 parent 6211986 commit f6db0b0

File tree

3 files changed

+36
-3
lines changed

3 files changed

+36
-3
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
"illuminate/contracts": "^11.0",
1313
"ext-json": "*",
1414
"illuminate/http": "^11.0",
15-
"matomo/device-detector": "^6.2"
15+
"matomo/device-detector": "^6.2",
16+
"ext-apcu": "*"
1617
},
1718
"require-dev": {
1819
"cego/php-cs-fixer": "2.0.0"

src/FilebeatLogging/ApcuCache.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
namespace Cego\FilebeatLogging;
4+
5+
use DeviceDetector\Cache\CacheInterface;
6+
7+
class ApcuCache implements CacheInterface
8+
{
9+
public function fetch(string $id)
10+
{
11+
return apcu_fetch($id);
12+
}
13+
14+
public function contains(string $id): bool
15+
{
16+
return apcu_exists($id);
17+
}
18+
19+
public function save(string $id, $data, int $lifeTime = 0): bool
20+
{
21+
return apcu_store($id, $data, $lifeTime);
22+
}
23+
24+
public function delete(string $id): bool
25+
{
26+
return apcu_delete($id);
27+
}
28+
29+
public function flushAll(): bool
30+
{
31+
return apcu_clear_cache();
32+
}
33+
}

src/FilebeatLogging/RequestProcessor.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
use Illuminate\Http\Request;
77
use DeviceDetector\ClientHints;
88
use DeviceDetector\DeviceDetector;
9-
use DeviceDetector\Cache\LaravelCache;
109
use Monolog\Processor\ProcessorInterface;
1110

1211
class RequestProcessor implements ProcessorInterface
@@ -83,7 +82,7 @@ private static function userAgentExtras(Request $request): array
8382
$clientHints = ClientHints::factory($headers);
8483

8584
$deviceDetector = new DeviceDetector($userAgent, $clientHints);
86-
$deviceDetector->setCache(new LaravelCache());
85+
$deviceDetector->setCache(new ApcuCache());
8786

8887
$deviceDetector->parse();
8988

0 commit comments

Comments
 (0)