Framework: [Request] Option to disable cache

Created on 16 Oct 2013  路  24Comments  路  Source: laravel/framework

I think it would be really useful to have an option to disable caching entirely -- or just do it when debug is set to true -- as it can cause headaches when developing. I'm surprised this doesn't already exist.

Most helpful comment

Change cache driver to array for the local environment.

I know this isn't exactly what you want but it should work.

All 24 comments

Change cache driver to array for the local environment.

I know this isn't exactly what you want but it should work.

See above :thumbsup:

This should be added on documentation.

This does not seem to work in Laravel 5.2, I have solved this by setting ENV variable CACHE_EXPIRE to -1 which is then used to set how many minutes is cache valid, this stops caching globally.

@cerw It did work here. Same version. Make sure you have this on your .env file: CACHE_DRIVER=array

None of your solution work

@vietnguyen09 perhaps you've cached your configuration (caching the .env), changing the .env has no effect until you clear the cached configuration.

Proof - none of the solutions above worked:

CACHE_DRIVER=array
CACHE_EXPIRE=-1

and then

php artisan cache:clear

Laravel cache system is stupid - why the hell I can't disable caching simply turning it off? Or probably I must override BladeCompiler and set it as IoC - but why, these are all needless actions, please make it simple for us.

@vietnguyen09 @arthurkushman I got the reason, try to disable the OPcache of php. It's work for me.

@moonsn Thanks!!! It's work for me too.

@moonsn what about if i don't have access to php?

@engnaguib sorry, i don't know. did you sure that your Opcache of php status is enable?

@moonsn i think it's enable because the laravel cache working

We wanted this as well and tried the 'extend' the cache facade and gave up (I wish I could have that afternoon back) and ended up creating our own class (OurCache::) that calls Cache:: and adding our additional logic there. However and packages that use Cache::* (for example Entrust), you're screwed. Also, Laravel Cache has little or no opportunity for injection and not to mention, Facades suck. If anyone had tips on escaping the tyranny of facades, please let up know.

If anyone had tips on escaping the tyranny of facades, please let up know.

The real problem here is that Library/Packages use them .. as well as global helper functions; isn't?

IMO libs/packages should never do this but here we are.

100% agree.

this works in Laravel 5.x:

  • in .env, set CACHE_DRIVER=none
  • add this to 'stores' in app\config\cache.php
        'none' => [
            'driver' => 'null',
        ],
  • add this at the top of app\Providers\AppServiceProvider.php
use Illuminate\Cache\NullStore;
use Cache;
  • add these lines to boot() function in app\Providers\AppServiceProvider.php
        Cache::extend( 'none', function( $app ) {
            return Cache::repository( new NullStore );
        } );
  • you may or may not need to run Artisan command config:cache, depending on your setup

@mrextreme's solution does not work for me in Laravel 5.8 ...

Seriously, there is no way to disable view caching in the dev environment ?

Changing the cache driver to array does not disable caching, and for instance if you change custom Blade directives, your templates are not updated and thus you have to _manually clear the view cache_. This is not a solution and this is really annoying.

@mrextreme's solution works fine for me on 5.8, except there is no need to add anything to a service provider - configuration only is enough. And that was enough even on 5.7.21. However this relates to cache facade. Blade caching is completely different.

@engnaguib sorry, i don't know. did you sure that your Opcache of php status is enable?

@moonsn Worked for me too ! Thanks

@mrextreme . I have same issue, i done your suggest, but it is not work in Laravel 5.8. Please help me if you can. thanks

Use this package, It will tackle all cache and clean it properly.

https://github.com/rakshitbharat/cleanify

The only thing that worked for me on Laravel 5.4 was to manually delete the cached views from the storage folder:
sudo rm -f storage/framework/views/*

So here is the problem that alludes most of us, the fact is; there are SIX caches in Laravel

_Change cache driver to array for the local environment._
^ This suggestion only effects 1 item (.1 The Data Cache) out of the 6 caches.

  1. The Data Cache

    • Configuration Files: /config/cache.php, .env
    • Env/Default: CACHE_DRIVER = 'file'
    • Config Key: config.cache.stores[CACHE_DRIVER]

    #### Cache Location (Drivers):

    • Driver: File > /storage/framework/cache as configured in config.cache.stores.file
    • Driver: Other > As configured in config.cache.stores.*

      Set By:

    • Cache::class : add, sear, put, set, putMany, putManyForever, forever, remember, rememberForever

      Cleared By:

    • Cache::class : forget, delete, deleteMultiple, clear (store->flush)
    • php artisan cache:clear (store->flush)
  2. The View Cache

    • Configuration Files: /config/view.php, .env
    • Env/Default: VIEW_COMPILED_PATH= 'realpath(storage_path('framework/views'))'
    • Config Key: config.view.compiled

    #### Cache Location:

    • /storage/framework/views

      Set By:

    • php artisan view:cache

      Cleared By:

    • php artisan view:clear
  3. The Config Cache

    • Configuration Files: .env
    • Env/Default: APP_CONFIG_CACHE= 'cache/config.php'

    #### Cache Location:

    • /bootstrap/cache/config.php

      Set By:

    • php artisan config:cache

      Cleared By:

    • php artisan config:clear
  4. The Route Cache

    • Configuration Files: .env
    • Env/Default: APP_ROUTES_CACHE= 'cache/routes-v7.php'

    #### Cache Location:

    • /bootstrap/cache/routes-v7.php

      Set By:

    • php artisan route:cache

      Cleared By:

    • php artisan route:clear
  5. The Event Cache

    • Configuration Files: .env
    • Env/Default: APP_EVENTS_CACHE= 'cache/events.php'

    #### Cache Location:

    • /bootstrap/cache/events.php

      Set By:

    • php artisan event:cache

      Cleared By:

    • php artisan event:clear
  6. Services & Packages Cache

    • Configuration Files: .env
    • Env/Default:

      • APP_SERVICES_CACHE = 'cache/services.php'

      • APP_PACKAGES_CACHE = 'cache/packages.php'

    #### Cache Locations:

    • /bootstrap/cache/services.php
    • /bootstrap/cache/packages.php

      Set By:

    • composer du

      Cleared By:

    • composer du
    • php artisan clear-compiled

How to clear all caches

Command optimize:clear will run commands numbered above 1,2,3,4,6 not 5

php artisan optimize:clear
php artisan event:clear

How to re-cache almost everything (optimize)

Command optimize will run commands numbered above 3,4 not 2,5 and 1,6 is cache on demand only.

php artisan optimize
php artisan event:cache
php artisan view:cache (Intensive, a view is cached on demand anyway)

A setting to disable caching of all of the above would be vastly appreciated!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kerbylav picture kerbylav  路  3Comments

klimentLambevski picture klimentLambevski  路  3Comments

jackmu95 picture jackmu95  路  3Comments

PhiloNL picture PhiloNL  路  3Comments

shopblocks picture shopblocks  路  3Comments