How to get list of all cached items by key in Laravel 5?

前端 未结 5 812
旧时难觅i
旧时难觅i 2021-02-19 10:01

The Cache class in laravel has methods such as get(\'itemKey\') to retrieve items from the cache, and remember(\'itemKey\', [\'myData1\', \'myData2\']) to save items in the cach

5条回答
  •  失恋的感觉
    2021-02-19 10:35

    ^This above dont work in LV 5.2

    Try this solution:

        $storage = \Cache::getStore(); // will return instance of FileStore
        $filesystem = $storage->getFilesystem(); // will return instance of Filesystem
        $dir = (\Cache::getDirectory());
        $keys = [];
        foreach ($filesystem->allFiles($dir) as $file1) {
    
            if (is_dir($file1->getPath())) {
    
                foreach ($filesystem->allFiles($file1->getPath()) as $file2) {
                    $keys = array_merge($keys, [$file2->getRealpath() => unserialize(substr(\File::get($file2->getRealpath()), 10))]);
                }
            }
            else {
    
            }
        }
    

提交回复
热议问题