Memcache for model cache

I have code like this one:

<?php
$block = Blocks::findFirst([
            'conditions' => 'bn = ?0 AND siteid = ?1',
            'bind' => [$bn, $sid],
            'cache' => ['key' => "{$sid}-{$bn}",],
        ]);

This block throws an exception if memcached fails. The point is that $block is false w\o mysql query. I have to try-catch for all such queries and repeat Blocks::findFirst w\o cache option. Are there any simpler ways to deal with memcache errors.

edited Oct '17

The most simplest solution - enable mysql result query cache, and don't care about cache parameter anymore.

Or create AbstractModel class and overwrite findFirst where you will check this connection to memcached, if it fails remove this cache argument .

But you should check out why exactly you have problem with connection to memcached.

Mysql tuning, methods overwriting are OK. But it isn't native solution. Btw, overwriting method can be difficult if i want do it not only for findFirst. Also i can't be sure that Memcache connection is living. It can fail during get or set calls. It's rare situation for normal production server, but it happens.

edited Oct '17

Yea but why you need cache when you will have mysql result cache enabled? There is no real difference memcache vs mysql result cache. Well there is if you will have many changes in table. Then okay. Well if you want do it for more then i guess this can be more difficult. Though you might just create your own cache adapter and add override methods there, just return null if not connected so query will be made.

Yes, my own cache adapter sounds good for me, thanks. I don't rely on mysql because it's the third app witch uses single DB. It's a single project, but splitted into 3 apps.