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

Cache Drive Backups #2060

Merged
merged 8 commits into from Jun 30, 2019
Merged

Conversation

MohKari
Copy link
Contributor

@MohKari MohKari commented Jun 18, 2019

Description
If our application is unable to connect to Redis, a CriticalError exception is now thrown.

CacheFactory catches the CriticalError exceptions that are thrown when Redis, Memcache and Predis fail to connect, it logs the exception and then attempts to initialize the backup cache driver (and if that fails it initializes dummy).

Checklist:

  • Securely signed commits
  • Component(s) with PHPdocs
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

…dummy' handler if $adapter->initialize() throws a CriticalError.

RedisHandler throws a CriticalError if there is an issue connecting to Redis.
@MohKari
Copy link
Contributor Author

MohKari commented Jun 18, 2019

Was originally pull request #2057, but i had some issues... So here it is again (Working this time hopefully).

@lonnieezell
Copy link
Member

I like the idea of this a lot. I made one comment on the code, but could you add the same process to the other drivers?

@MohKari
Copy link
Contributor Author

MohKari commented Jun 20, 2019

@lonnieezell I've attempted to implement a similar process for the other drives as requested.

The DummyHander, FileHander and WincacheHandler's initialize() method contain no logic, so I have ignored these.

I modelled my solution on how PredisHandler initialize() method, so I've just added some comments there.

I've changed MemcachedHandler initialize() a fair bit, I've broken it down into two sections contained within the if/elseif block.

I've tested the Redis, Predis, Memcached drivers and I'm happy with how they work (If they can't connect to the cache server, they throw a CriticalError exception). I'm unable to test the Memcache driver (I can't seem to get it to work with PHP 7+).

I'm confident with the code I've written to check if the cache server is contactable when using Memcache, I followed https://www.php.net/manual/en/memcache.connect.php, which suggests that if connect() returns false, the sever can not be contacted, which will trigger our CriticalError exception.

Is it worth performing similar checks on the Handlers I've ignored? Or does the isSupported() method handle it?

@lonnieezell
Copy link
Member

I believe isSupported should be sufficient, but it's been a while since I've been in those handlers, honestly.

Thanks for this!

In the future, though, we would prefer to have signed commits. There's instructions in the docs to help with that.

@lonnieezell lonnieezell merged commit 8401bac into codeigniter4:develop Jun 30, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants