\Charcoal\App\MiddlewareCacheMiddleware

The cache loader middleware attempts to load cache from the request's path (route).

It should be run as the first middleware of the stack, in most cases. (With Slim, this means adding it last)

There is absolutely no extra configuration or dependencies to this middleware. If the cache key exists, then it will be injected in the response body and returned.

Note that if the cache is hit, the response is directly returned; meaning the rest of the middilewares in the stack will be ignored

It is up to other means, such as the provided CacheGeneratorMiddleware, to set this cache entry.

Summary

Methods
Properties
Constants
__construct()
__invoke()
No public properties found
No constants found
No protected methods found
No protected properties found
N/A
cacheKey()
isActive()
isPathIncluded()
isPathExcluded()
isQueryIncluded()
isQueryExcluded()
parseIgnoredParams()
$cachePool
$cacheTtl
$includedPath
$excludedPath
$methods
$statusCode
$includedQuery
$excludedQuery
$ignoredQuery
$headers
N/A

Properties

$cachePool

$cachePool : \Charcoal\App\Middleware\CacheItemPool

PSR-6 cache item pool.

Type

\Charcoal\App\Middleware\CacheItemPool

$cacheTtl

$cacheTtl : integer

Type

integer

$includedPath

$includedPath : string

Type

string

$excludedPath

$excludedPath : string

Type

string

$methods

$methods : array<mixed,string>

Type

array<mixed,string>

$statusCode

$statusCode : array<mixed,integer>

Type

array<mixed,integer>

$includedQuery

$includedQuery : array|string|null

Type

array|string|null

$excludedQuery

$excludedQuery : array|string|null

Type

array|string|null

$ignoredQuery

$ignoredQuery : array|string|null

Type

array|string|null

$headers

$headers : boolean

Type

boolean

Methods

__construct()

__construct(array  $data) 

Parameters

array $data

Constructor dependencies and options.

__invoke()

__invoke(\Psr\Http\Message\RequestInterface  $request, \Psr\Http\Message\ResponseInterface  $response, callable  $next) : \Psr\Http\Message\ResponseInterface

Load a route content from path's cache.

This method is as dumb / simple as possible. It does not rely on any sort of settings / configuration. Simply: if the cache for the route exists, it will be used to display the page. The $next callback will not be called, therefore stopping the middleware stack.

To generate the cache used in this middleware, @see \Charcoal\App\Middleware\CacheGeneratorMiddleware.

Parameters

\Psr\Http\Message\RequestInterface $request

The PSR-7 HTTP request.

\Psr\Http\Message\ResponseInterface $response

The PSR-7 HTTP response.

callable $next

The next middleware callable in the stack.

Returns

\Psr\Http\Message\ResponseInterface

cacheKey()

cacheKey(string  $path, array  $queryParams) : string

Parameters

string $path

The query path (route).

array $queryParams

The query parameters.

Returns

string

isActive()

isActive(\Psr\Http\Message\RequestInterface  $request, \Psr\Http\Message\ResponseInterface  $response) : boolean

Parameters

\Psr\Http\Message\RequestInterface $request

The PSR-7 HTTP request.

\Psr\Http\Message\ResponseInterface $response

The PSR-7 HTTP response.

Returns

boolean

isPathIncluded()

isPathIncluded(string  $path) : boolean

Parameters

string $path

The request path (route) to verify.

Returns

boolean

isPathExcluded()

isPathExcluded(string  $path) : boolean

Parameters

string $path

The request path (route) to verify.

Returns

boolean

isQueryIncluded()

isQueryIncluded(array  $queryParams) : boolean

Parameters

array $queryParams

The query parameters.

Returns

boolean

isQueryExcluded()

isQueryExcluded(array  $queryParams) : boolean

Parameters

array $queryParams

The query parameters.

Returns

boolean

parseIgnoredParams()

parseIgnoredParams(array  $queryParams) : array

Parameters

array $queryParams

The query parameters.

Returns

array