Skip to content

Latest commit

 

History

History
101 lines (79 loc) · 3.16 KB

CachedRouter.md

File metadata and controls

101 lines (79 loc) · 3.16 KB

Atanvarno\Router\CachedRouter

Implementation of Router using a PSR-16 cache.

class CachedRouter extends SimpleRouter
{
    // Methods
    public function __construct(CacheInterface $cache, string $cacheKey = 'routerData', $driver = Router::DRIVER_GROUP_COUNT, array $routes = [], bool $cacheDisable = false)
    public function add($methods, string $pattern, $handler): Router
    public function addGroup(string $patternPrefix, array $routes): Router
    public function connect(string $pattern, $handler): Router
    public function delete(string $pattern, $handler): Router
    public function dispatch(RequestInterface $request, bool $exceptions = false): array
    public function get(string $pattern, $handler): Router
    public function head(string $pattern, $handler): Router
    public function options(string $pattern, $handler): Router
    public function patch(string $pattern, $handler): Router
    public function post(string $pattern, $handler): Router
    public function purge(string $pattern, $handler): Router
    public function put(string $pattern, $handler): Router
    public function refreshCache(): bool
    public function trace(string $pattern, $handler): Router
}

Extends SimpleRouter.

__construct

Builds a CachedRouter instance.

__construct(CacheInterface $cache, string $cacheKey = 'routerData', $driver = Router::DRIVER_GROUP_COUNT, array $routes = [], bool $cacheDisable = false)

Parameters

  • CacheInterface $cache

    Required. PSR-16 cache to use.

  • string $cacheKey

    Optional. Defaults to 'routerData'. Key to use for cached data.

  • string $driver

    Optional. Defaults to Router::DRIVER_GROUP_COUNT. FastRoute driver. You should use the Router::DRIVER_* constants.

  • array $routes

    Optional. Defaults to []. Array of add() parameter values.

  • bool $cacheDisable

    Optional. Defaults to false. Disable cache functionality.

Throws

Returns

  • CachedRouter

refreshCache

Generates dispatch data and caches it.

public function refreshCache(): bool

This is useful if the routes configuration has changed, for example.

Note this method will still work when $cacheDisable = true has been passed to the constructor.

Parameters

None.

Throws

Nothing is thrown.

Returns