Search code examples
phplaravellaravel-artisan

How to clear PHP artisan cache for a single entry instead of everything


Usually when I want to clear app cache I run php artisan cache:clear but that removes all cache entries. What I'm hoping to do is forget a single element from command line by specifying the key. For example, something like php artisan cache:clear --key=userids.

I looked through some documentation but couldn't find anything. Is this possible and if so how?


Solution

  • There is no php artisan cache:clear --key=userids command that I am aware of but you can delete a particular cache using tinker. Just run

    php artisan tinker
    Psy Shell v0.10.8 (PHP 8.0.6 — cli) by Justin Hileman
    >>> Cache::get('me');
    => "I am Sandeep"
    >>> Cache::forget('me');
    => true
    >>> Cache::get('me');
    => null