Overview

Namespaces

  • Charcoal
    • App
      • Action
      • Config
      • Handler
      • Middleware
      • Module
      • Route
      • Script
      • ServiceProvider
      • Template

Classes

  • CacheMiddleware
  • Overview
  • Namespace
  • Class

Class CacheMiddleware

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.

Namespace: Charcoal\App\Middleware
Located at Charcoal/App/Middleware/CacheMiddleware.php
Methods summary
public
# __construct( array $data )

Parameters

$data
Constructor dependencies and options.
public Psr\Http\Message\ResponseInterface
# __invoke( Psr\Http\Message\RequestInterface $request, Psr\Http\Message\ResponseInterface $response, callable $next )

Load a route content from path's cache.

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

$request
The PSR-7 HTTP request.
$response
The PSR-7 HTTP response.
$next
The next middleware callable in the stack.

Returns

Psr\Http\Message\ResponseInterface
API documentation generated by ApiGen