简体   繁体   English

Laravel 5:忘记缓存无法正常工作

[英]Laravel 5: forget cache not working

I try to delete specific cached data using: 我尝试使用以下方法删除特定的缓存数据:

Cache::forget('key');

also tried 也试过了

Cache::pull('key');

but cache still existed in DB 但缓存仍然存在于DB中

note: I'm using Database cache, and Laravel 5.1.7 注意:我正在使用数据库缓存和Laravel 5.1.7

我找到了答案,问题发生的原因是我从带有prefix DB复制cache密钥,而Laravel通常会添加另一个prefix ,并且它永远不会匹配

Try php artisan cache:clear 试试php artisan cache:清楚

on command line 在命令行上

If someone needs it, my problem was because of file permissions. 如果有人需要它,我的问题是因为文件权限。 So, you can try this command in the root of the project chmod -R 755 . 因此,您可以在项目chmod -R 755 .的根目录中尝试此命令chmod -R 755 . . However, I did chmod -R 777 . 但是,我做了chmod -R 777 . , but that's not recommended. ,但不建议这样做。

For the records: if you are using cache tags , the forget method will not work. 对于记录:如果使用缓存标记 ,则forget方法将不起作用。 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";
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM