Implementing ESI with OctoberCMS - Looking for howto

I’ve been working on integrating ESI (Edge Side Includes) into my OctoberCMS project and have run into some challenges. My aim is to have certain dynamic parts of my site uncached, while the rest benefits from caching, hence the need for ESI.

So far, here’s what I’ve attempted:

  1. Custom Middleware: I created custom middleware named NoCacheMiddleware to set no-cache headers for specific routes. However, I encountered the “Target class does not exist” error even after confirming the namespace and directory structure.
  2. Composer Autoload: Tried regenerating Composer’s autoload with composer dump-autoload and also cleared the OctoberCMS cache.
  3. Using barryvdh/laravel-httpcache: I thought this package might simplify the integration as it provides tools for ESI in Laravel. I followed the package documentation, enabled ESI in the config, added the required middleware, and set up routes for ESI includes. However, I kept encountering various issues like a “Call to undefined method” error.

I’ve also ensured the web server supports ESI, and I believe my setup respects OctoberCMS conventions.

Has anyone successfully implemented ESI with OctoberCMS? If so, could you share how you achieved it or provide any insights on where I might be going wrong? Any help or pointers would be greatly appreciated.

I’m unsure if this is useful, but it may be relevant. You can change the default middleware in the cms.php and backend.php configuration files.

/*
|--------------------------------------------------------------------------
| Middleware Group
|--------------------------------------------------------------------------
|
| The name of the middleware group to apply to all CMS application routes.
| You may use this to apply your own middleware definition, or use some
| of the defaults: web, api
|
*/

'middleware_group' => 'web',