Welcome Guest, Not a member yet? Register   Sign In
Display a custom error if the cache driver fails
#1

What would be the best way to display a custom error message when the cache driver fails (Memcached in my case)?

I thought of creating a FILTER, and within this filter testing the ->getCacheInfo() method. Does this seem correct?

Like this:
Config\Filters.php

PHP Code:
public array $aliases = [
        'csrf'          => CSRF::class,
        'toolbar'      => DebugToolbar::class,
        'honeypot'      => Honeypot::class,
        'invalidchars'  => InvalidChars::class,
        'secureheaders' => SecureHeaders::class,
        'authentication' => AuthenticationFilter::class,
[
b]        'verifyCache'  => VerifyMemcachedFilter::class,
[/
b]    ];
public array 
$globals = [
        'before' => [
            'verifyCache',],

]; 


Filters\VerifyMemCachedFilter.php
PHP Code:
    public function before(RequestInterface $request$arguments null)
    {
        $cache Services::cache();
        if ($cache->getCacheInfo() === null) {
            echo 'MEMCACHED not started';
            die;
        }
    
Reply




Theme © iAndrew 2016 - Forum software by © MyBB