Disable CodeIgniter 4 Cache Handler During Development

We recently ran into an issue where CodeIgniter’s cache() produced unexpected results during development. Our problem was forgetting to change the cache handler from ‘file’ to ‘dummy’ outside of the production environment. So we do not have to remember to change the handler, we modified our App’s Config\Cache::handler as follows…

public string $handler = (ENVIRONMENT === 'production') ? 'file' : 'dummy';

That one simple “set it and forget it” change could have saved wasted time spent debugging the problem.

Update: While discussing this with other developers, one alternative would be updating the .env file.

CI_ENVIRONMENT = development
cache.handler = 'dummy'

This way CI_ENVIRONMENT and cache.handler can be updated together.

# CI_ENVIRONMENT = development
# cache.handler = 'dummy'

Note: I personally prefer our original solution, which shouldn’t ever cause a problem, but one of the main CI contributors prefers using .env so we will stick with their advice 😉

Leave a Reply

Your email address will not be published. Required fields are marked *