Skip to content

Commit

Permalink
Use apcu instead of laravel cache (#32)
Browse files Browse the repository at this point in the history
* Use apcu instead of laravel cache

* Cs fix
  • Loading branch information
LauJosefsen authored Jul 3, 2024
1 parent 6211986 commit f6db0b0
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"illuminate/contracts": "^11.0",
"ext-json": "*",
"illuminate/http": "^11.0",
"matomo/device-detector": "^6.2"
"matomo/device-detector": "^6.2",
"ext-apcu": "*"
},
"require-dev": {
"cego/php-cs-fixer": "2.0.0"
Expand Down
33 changes: 33 additions & 0 deletions src/FilebeatLogging/ApcuCache.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace Cego\FilebeatLogging;

use DeviceDetector\Cache\CacheInterface;

class ApcuCache implements CacheInterface
{
public function fetch(string $id)
{
return apcu_fetch($id);
}

public function contains(string $id): bool
{
return apcu_exists($id);
}

public function save(string $id, $data, int $lifeTime = 0): bool
{
return apcu_store($id, $data, $lifeTime);
}

public function delete(string $id): bool
{
return apcu_delete($id);
}

public function flushAll(): bool
{
return apcu_clear_cache();
}
}
3 changes: 1 addition & 2 deletions src/FilebeatLogging/RequestProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use Illuminate\Http\Request;
use DeviceDetector\ClientHints;
use DeviceDetector\DeviceDetector;
use DeviceDetector\Cache\LaravelCache;
use Monolog\Processor\ProcessorInterface;

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

$deviceDetector = new DeviceDetector($userAgent, $clientHints);
$deviceDetector->setCache(new LaravelCache());
$deviceDetector->setCache(new ApcuCache());

$deviceDetector->parse();

Expand Down

0 comments on commit f6db0b0

Please sign in to comment.