Skip to content

Commit 01ba5e8

Browse files
committed
Use amphp/cache instead of lrucache
1 parent f9dd116 commit 01ba5e8

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@
2727
],
2828
"require": {
2929
"php": ">=8.1",
30+
"amphp/cache": "^2",
3031
"amphp/http-server": "^3",
3132
"amphp/http": "^2-dev",
3233
"amphp/socket": "^2",
33-
"nikic/fast-route": "^1",
34-
"cash/lrucache": "^1"
34+
"nikic/fast-route": "^1"
3535
},
3636
"require-dev": {
3737
"amphp/log": "^2",

src/Router.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
namespace Amp\Http\Server;
44

5+
use Amp\Cache\LocalCache;
56
use Amp\Http\HttpStatus;
67
use Amp\Http\Server\RequestHandler\ClosureRequestHandler;
7-
use cash\LRUCache;
88
use FastRoute\Dispatcher;
99
use FastRoute\RouteCollector;
1010
use function FastRoute\simpleDispatcher;
@@ -27,7 +27,7 @@ final class Router implements RequestHandler
2727

2828
private string $prefix = "/";
2929

30-
private readonly LRUCache $cache;
30+
private readonly LocalCache $cache;
3131

3232
/**
3333
* @param int $cacheSize Maximum number of route matches to cache.
@@ -46,7 +46,7 @@ public function __construct(
4646
throw new \ValueError("The number of cache entries must be greater than zero");
4747
}
4848

49-
$this->cache = new LRUCache($cacheSize);
49+
$this->cache = new LocalCache($cacheSize);
5050
}
5151

5252
/**
@@ -61,7 +61,7 @@ public function handleRequest(Request $request): Response
6161

6262
if (null === $match = $this->cache->get($toMatch)) {
6363
$match = $this->routeDispatcher->dispatch($method, $path);
64-
$this->cache->put($toMatch, $match);
64+
$this->cache->set($toMatch, $match);
6565
}
6666

6767
switch ($match[0]) {

0 commit comments

Comments
 (0)