I try to delete specific cached data using:
Cache::forget('key');
also tried
Cache::pull('key');
but cache still existed in DB
note: I'm using Database cache, and Laravel 5.1.7
The following is the syntax to clear cache in Laravel is given below: php artisan cache: clear. php artisan config: clear. php artisan cache: clear.
To clear all Laravel's cache, just run the following command: $ php artisan optimize:clear Compiled views cleared! Application cache cleared!
Click Ctrl-A to highlight all the files in the folder and then Ctrl-click cache. ini so it is deselected. Delete all the files. This will leave you with only the cache.
I found the answer, the problem happen because I copy cache
key from DB with prefix
, and Laravel normally add another prefix
, and it will never matched
For the records: if you are using cache tags, the forget
method will not work. This is what I managed to do to solve the problem:
$cache_key = "MY_CACHE_KEY";
$cache_tags = ["MY_CACHE_TAG"]; //SOMETIMES I USE MULTIPLE TAGS
if (\Cache::tags($cache_tags)->has($cache_key)) {
\Cache::tags($cache_tags)->forget($cache_key);
$results = "CACHE item " . $cache_key . " forgotten";
} else {
$results = "Key " . $cache_key . " IS NOT CACHED";
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With