CakePHP 3 - Best Practice and Cookbook

UP: TOC

This article describes how content can be written from Cakephp Middleware to REDIS in order to enable caching.

We assume that REDIS is already installed.

Extend CakePHP with its Middleware

Create a file ../src/Middleware/CacheMiddleware.php

body()) === 0) return;
 
      // do not cache certain URLs
      if (substr($request->url,0,5) === 'admin') return;
 
      error_log('CacheMiddleware called, wrote key:' . md5('prefix/'. $request->url));

      Cache::write(md5('prefix/'. $request->url), $response->body() , 'default');
        
      return $response;
   }
}
?>
UP: TOC