Mark Garratt

Mark Garratt

Who am I?

Web Developer based in London, UK

What I write about

Recent Posts

Disable Laravel Cache

In a project I was working on today there was a bug in some output that is heavily cached. Clearing the cache manually via php artisan cache:clear would have been too time consuming, so I needed a way to disable caching.

After a quick search on Google I found this issue. It explains that the best thing to do in Laravel is to us an in-memory cache using the array driver instead of disabling caching entirely. There are two ways to accomplish this in Laravel 5.* either edit your local .env file (preferred) or edit the config files as you would in Laravel 4.*. You could also edit an environment config file.

# /.env


# /config/cache.php     <= Laravel 5.*
# /app/config/cache.php <= Laravel 4.*

return [
    // ...
    'default' => 'array',
    // ...

By doing it this way you are still getting a fresh cache on each request but, you still use all of the cache methods such as Cache::add() and Cache::remember(). This allows you to test defaults and values that you expect to have been placed in the cache by functions that have been called earlier in the request.