Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fallback in case connection fail #135

Open
choks87 opened this issue Sep 17, 2018 · 2 comments
Open

Fallback in case connection fail #135

choks87 opened this issue Sep 17, 2018 · 2 comments

Comments

@choks87
Copy link

@choks87 choks87 commented Sep 17, 2018

It would be good if we could have a fallback adapter (NullAdapter) in the case when some adapter fails to connect.

Ex. if Redis adapter throws ConnectionException and if the fallback option is set, no exception is thrown, but it will use NullAdapter.

Right now, if Redis is not available, app dies.
This could be achieved by adding some listeners directly in the app, and catch block, but if autowiring is used, it will fail.

example config:

cache_adapter:
    fallback_provider: @cache.provider.void
    providers:
        redis:
            factory: cache.factory.redis
            options:
                host: '%env(REDIS_HOST)%'
                port: '%env(REDIS_PORT)%'
         void:
            factory: cache.factory.void
@choks87 choks87 changed the title Fallback Fallback Provider in case connection fail Sep 17, 2018
@choks87 choks87 changed the title Fallback Provider in case connection fail Fallback in case connection fail Sep 17, 2018
@sbol-coolblue
Copy link

@sbol-coolblue sbol-coolblue commented Nov 5, 2018

I'm not expert on these libraries, but it looks like you can get very close to this behaviour already via the CachePoolChain.

In the $options constructor array you can pass a 'skip_on_failure' option. If true, this will cause Chain to capture the exceptions, remove the Pool causing them from the Chain and log a warning. If you add a VoidCachePool to the end of the chain it will be the only one left after the Redis pool fails, effectively giving you the behavior you want.

There is one tiny caveat to this solution: cache writes will be duplicated into the VoidCachePool as well... but the performance impact should be quite negligible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.