Laravel 文件缓存:我们可以设置文件权限吗?

Laravel file cache: can we set file permissions?

我问你是否有可能向 config/cache.php 添加权限掩码,以便使用 664 而不是 644 作为文件权限掩码创建新的缓存文件。

我的 shell 用户也是 www-data 组的成员,但是使用 644,shell 用户无法删除缓存。

您可以创建新的文件缓存存储实例或自定义缓存驱动程序。然后设置权限。

Laravel File Store Documentation

__construct(Filesystem $files, string $directory, int|null $filePermission = null)

$filePermission 接受 int|null

namespace App\Extensions;

use Illuminate\Contracts\Cache\Store;

class CustomStore implements Store
{
  public function __construct(Filesystem $files, string $directory, int|null $filePermission = null) {}
  public function get($key) {}
  public function many(array $keys) {}
  public function put($key, $value, $seconds) {}
  public function putMany(array $values, $seconds) {}
  public function increment($key, $value = 1) {}
  public function decrement($key, $value = 1) {}
  public function forever($key, $value) {}
  public function forget($key) {}
  public function flush() {}
  public function getPrefix() {}
}

创建自定义缓存驱动后,可以注册查看instructions