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

[Request] Option to disable cache #2501

Closed
johnmaguire opened this issue Oct 16, 2013 · 30 comments
Closed

[Request] Option to disable cache #2501

johnmaguire opened this issue Oct 16, 2013 · 30 comments

Comments

@johnmaguire
Copy link

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.

@bonzai
Copy link
Contributor

bonzai commented Oct 16, 2013

Change cache driver to array for the local environment.

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

@taylorotwell
Copy link
Member

See above 👍

@agiannis
Copy link

agiannis commented Jun 1, 2016

This should be added on documentation.

@cerw
Copy link

cerw commented Sep 15, 2016

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.

@hudsonpereira
Copy link

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

@vietnguyen09
Copy link

None of your solution work

@nickels
Copy link

nickels commented Aug 2, 2017

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

@arthurkushman
Copy link

arthurkushman commented Oct 16, 2017

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.

@moonsn
Copy link

moonsn commented Jan 10, 2018

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

@heldermattos
Copy link

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

@engnaguib
Copy link

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

@moonsn
Copy link

moonsn commented Jun 7, 2018

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

@engnaguib
Copy link

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

@jschlies
Copy link

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.

@mfn
Copy link
Contributor

mfn commented Sep 18, 2018

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.

@jschlies
Copy link

100% agree.

@mrextreme
Copy link

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

@tchapi
Copy link

tchapi commented Apr 24, 2019

@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.

@TivoSoho
Copy link

@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.

@jicao
Copy link

jicao commented May 9, 2019

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

@moonsn Worked for me too ! Thanks

@liemleitvn
Copy link

@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

@rakshitbharat
Copy link
Contributor

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

https://github.com/rakshitbharat/cleanify

@schwemmer
Copy link

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/*

@marcnewton
Copy link

marcnewton commented Jul 25, 2020

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!

@SiL3NC3
Copy link

SiL3NC3 commented Sep 3, 2021

So any news on this topic?
During developing disabling the full cache would be so useful!

@mubahood
Copy link

If you are using MAMP, disable OPCache under Preferences, General, PHP-Cahce. just select off. thank me later.

@JamesThanna
Copy link

Being able to disable caching of routes when a application is in dev mode would be ideal. Running route:cache each time to clear cache when in development doesn't make any sense if the site is already in development mode.

@lk77
Copy link

lk77 commented Mar 2, 2023

Simply do route:clear, and you won't have any cache, you can do optimize:clear to clear everything

@verybigelephants
Copy link

verybigelephants commented Nov 26, 2023

just tried this and this doesn't seem wo work in laravel 10

this is a huge problem when developing on shared hosting environmnts that cache files :(

@bridgeyuwa
Copy link

Started using cache for my project to improve performance and the inability to disable cache when needed in laravel 11 is hindering my progress.

Any direct solution yet?

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

No branches or pull requests