Ronster's avatar

Custom cache driver in 5.5

Hi,

I have 2 other apps running on 5.3 and both are using this cache driver: https://github.com/ethanhann/Laravel-RedisStore

i am creating a 3rd app and want to use the same cache driver but in laravel 5.5 i'm constantly getting an error saying that Driver [ehann-redis] is not supported.

the thing is that as soon as i change the redis.driver config value to ehann-redis] it's immediately failing. the AppServiceProvider's boot method is not even beeing called. also my custom CacheServiceProvider.php file isn't beeing called.

AppServiceProvider.php

Cache::extend('ehann-redis', function ($app) {
            return Cache::repository(new \Ehann\Cache\RedisStore(
                $app['redis'],
                $app['config']['cache.prefix'],
                $app['config']['cache.stores.redis.connection']
            ));
        });

config/cache.php

'redis' => [
            'driver' => 'ehann-redis',
            'connection' => 'default',
        ]

I also logged an issue on this in november but nothing happened on that.

Does anybody expierenced the same or has an idea how to get this fixed?

thanks

0 likes
5 replies
bobbybouwmann's avatar

Did you add this bit of code to the boot method or the register method? It should be the boot method!

Ronster's avatar

It's in the boot method.

It looks like it's calling the resolve method on the CacheManager before the extend method is beeing called.

ChrisB's avatar

It's a chicken/egg issue, where your custom cache driver is not initialized before other services using it are booted.

In the case of the issue you posted related to the laravel-permission package, I've posted solution there: disable auto-discovery for that package, and then specify the boot order by adding the package in the order you want it, via config/app.php

https://github.com/spatie/laravel-permission/issues/630#issuecomment-359935018

1 like

Please or to participate in this conversation.