Skip to content

Commit

Permalink
Use amphp/cache instead of lrucache
Browse files Browse the repository at this point in the history
  • Loading branch information
trowski committed Feb 2, 2023
1 parent f9dd116 commit 01ba5e8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@
],
"require": {
"php": ">=8.1",
"amphp/cache": "^2",
"amphp/http-server": "^3",
"amphp/http": "^2-dev",
"amphp/socket": "^2",
"nikic/fast-route": "^1",
"cash/lrucache": "^1"
"nikic/fast-route": "^1"
},
"require-dev": {
"amphp/log": "^2",
Expand Down
8 changes: 4 additions & 4 deletions src/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace Amp\Http\Server;

use Amp\Cache\LocalCache;
use Amp\Http\HttpStatus;
use Amp\Http\Server\RequestHandler\ClosureRequestHandler;
use cash\LRUCache;
use FastRoute\Dispatcher;
use FastRoute\RouteCollector;
use function FastRoute\simpleDispatcher;
Expand All @@ -27,7 +27,7 @@ final class Router implements RequestHandler

private string $prefix = "/";

private readonly LRUCache $cache;
private readonly LocalCache $cache;

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

$this->cache = new LRUCache($cacheSize);
$this->cache = new LocalCache($cacheSize);
}

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

if (null === $match = $this->cache->get($toMatch)) {
$match = $this->routeDispatcher->dispatch($method, $path);
$this->cache->put($toMatch, $match);
$this->cache->set($toMatch, $match);
}

switch ($match[0]) {
Expand Down

0 comments on commit 01ba5e8

Please sign in to comment.