Framework: [L5.7] Cache clear fails

Created on 5 Sep 2018  路  32Comments  路  Source: laravel/framework

  • Laravel Version: 5.7.1
  • PHP Version: 7.2.9
  • Database Driver & Version: MariaDB 10.2.16.

Description:

Attempting to clear app cache returns an error message:
Failed to clear cache. Make sure you have the appropriate permissions.

Steps To Reproduce:

$ php artisan cache:clear

Most helpful comment

The "data" directory (storage/framework/cache/data) doesn't exist by default, which causes the check at https://github.com/laravel/framework/blob/9c844aa37617d8694ba364e16a5f26ecc470c18e/src/Illuminate/Cache/FileStore.php#L144-L146 to fail and return false, which in turn causes https://github.com/laravel/framework/blob/9c844aa37617d8694ba364e16a5f26ecc470c18e/src/Illuminate/Cache/Console/ClearCommand.php#L71-L73 to error out.

All 32 comments

What cache driver are you using, and do you have the appropriate permissions?

Hi,
I too have the same problem after a new installation of laravel.

My cache drive is file.
storage/framework/cache permissions: drwxrwxr-x

Same here on Mac...

The "data" directory (storage/framework/cache/data) doesn't exist by default, which causes the check at https://github.com/laravel/framework/blob/9c844aa37617d8694ba364e16a5f26ecc470c18e/src/Illuminate/Cache/FileStore.php#L144-L146 to fail and return false, which in turn causes https://github.com/laravel/framework/blob/9c844aa37617d8694ba364e16a5f26ecc470c18e/src/Illuminate/Cache/Console/ClearCommand.php#L71-L73 to error out.

I have this issue as well after upgrading to 5.7

php artisan cache:clear works fine for me, but with any option it doesnt.
php artisan cache:clear --tags=views fails with the message Failed to clear cache. Make sure you have the appropriate permissions.
Tried adding the data directory, but that does not help.

I am using redis for all caches.

When using redis with tags, the error is caused at https://github.com/laravel/framework/blob/544b75943c055ec7e6318cb00ec53d5cc8661aa5/src/Illuminate/Cache/RedisTaggedCache.php#L82-L88
This method should return a bool, but returns nothing, which evaluates to false and triggers the error.
Cache clearing should still work fine, but the cache:cleared event won't fire.

Also, when using the DB store, https://github.com/laravel/framework/blob/544b75943c055ec7e6318cb00ec53d5cc8661aa5/src/Illuminate/Cache/DatabaseStore.php#L222-L225 will return false if the cache table is already empty, leading to the same kind of misleading error message.

same cache problem here, how can solve it?

@alkapatel If you're using the file store driver, create the _storage/framework/cache/data_ directory manually.

@taylorotwell closed this but a fresh install of laravel 5.7 today gave me this same issue. What am I missing?

@taylorotwell same here

@tramel-woodard , @elias-alea you need to create storage/framework/cache/data directory manually like @AegirLeet said.

@tramel-woodard , @elias-alea you need to create storage/framework/cache/data directory manually like @AegirLeet said.

Thanks loads. Quick question, how do I know which solutions to trust? The ones closed by contributors?
Also, I think this information could be added to the documentation here: https://laravel.com/docs/5.7/cache#configuration

Thanks

@elias-alea If you install laravel now, you will get storage/framework/cache/data directory automatically so you don't have to create it. They leave this directory to allow the filesystem to cache.

@phannaly noted, awesome!
@taylorotwell and team, thanks loads, you are the men!

The upgrade guide has now a reference to the missing data/ directory (section "Cache")

SI, al agregar esta carpeta data, este problema queda solucionado, Muchas Gracias

por los que aun tienen el problema del cache yo lo solucione como dice la guia de instalacion, use lo siguiente:
mkdir -p storage/framework/cache/data;
y luego
cp storage/framework/cache/.gitignore storage/framework/cache/data/.gitignore
y listo ya esta con esto

Thanks @gabriel9944

Just only add folder name "data" in storage/framework/cache/ and try php artisan cache:clear.

I don't understand why I am directed to read the documentation and/or upgrade guide when the framework could just as easily (re)create folders, particularly cache file locations, that it requires to exist, if they aren't present. The fact that Laravel developers need several empty folders to exist in the repository with a .gitignore only is kind of silly. Why doesn't php artisan cache:clear just create these folders if they don't exist but are required for the framework to operate?

the same issue, however, the "storage/framework/cache/data" folder exists.
[laravel]$ php artisan cache:clear
Failed to clear cache. Make sure you have the appropriate permissions.

Laravel Framework 5.7.18
PHP 7.2.13
10.1.37-MariaDB

any suggestions?

@alterman1994 I would chown it and/or chmod it (recursively) if needed, to the user running artisan command. If it got created by www-data, it can give permissions issue when running as logged in user. On our servers (Ubuntu) we add ubuntu, root, www-data to www-group and chown group ownership to www-group. HTH-

Wouldn't it be smart if laravel created the data directory on cache:clear automatically if it doesn't exist?

same cache problem here, how can solve it?

Hi Babs!
Please check your cache path i think you are missing local folder in after stroage. Follow this path and it will fix the problem

cache.php

'file' => [
'driver' => 'file',
'path' => storage_path('local/framework/cache/data'),
],

For me

php artisan cache:clear

command worked after

php artisan config:cache

command. It worked :/

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

https://github.com/rakshitbharat/cleanify

Hey,

I am following below blog documentation it's working well

https://medium.com/@tiwarishani/laravel-clear-cache-config-view-and-routes-48644a0f9367

This solved issue for me :)

mkdir storage/framework/cache/data

Laracasts source via @bobbybouwmann

Me i resolve this problem with php artisan config:cache and after php artisan cache:clear

Hey everyone,

I'm locking this issue because it either has gone off-topic, become a dumping ground for things which shouldn't be in an issue tracker or is just too old. Please try to discuss things further on one of the below channels:

Was this page helpful?
0 / 5 - 0 ratings

Related issues

klimentLambevski picture klimentLambevski  路  3Comments

kerbylav picture kerbylav  路  3Comments

lzp819739483 picture lzp819739483  路  3Comments

PhiloNL picture PhiloNL  路  3Comments

shopblocks picture shopblocks  路  3Comments