Skip to content

Commit

Permalink
[10.x] Allow separate directory for locks on filestore (laravel#46811)
Browse files Browse the repository at this point in the history
* allow separate directory for locks on filestore

* fix style

* fix method signature

* Update src/Illuminate/Cache/FileStore.php

Co-authored-by: Dries Vints <[email protected]>

* apply styleci

* formatting

---------

Co-authored-by: Dries Vints <[email protected]>
Co-authored-by: Taylor Otwell <[email protected]>
  • Loading branch information
3 people authored Apr 18, 2023
1 parent e838b1d commit 7aab67d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/Illuminate/Cache/CacheManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,10 @@ protected function createArrayDriver(array $config)
*/
protected function createFileDriver(array $config)
{
return $this->repository(new FileStore($this->app['files'], $config['path'], $config['permission'] ?? null));
return $this->repository(
(new FileStore($this->app['files'], $config['path'], $config['permission'] ?? null))
->setLockDirectory($config['lock_path'] ?? null)
);
}

/**
Expand Down
29 changes: 28 additions & 1 deletion src/Illuminate/Cache/FileStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ class FileStore implements Store, LockProvider
*/
protected $directory;

/**
* The file cache lock directory.
*
* @var string|null
*/
protected $lockDirectory;

/**
* Octal representation of the cache file permissions.
*
Expand Down Expand Up @@ -210,7 +217,14 @@ public function forever($key, $value)
*/
public function lock($name, $seconds = 0, $owner = null)
{
return new FileLock($this, $name, $seconds, $owner);
$this->ensureCacheDirectoryExists($this->lockDirectory ?? $this->directory);

return new FileLock(
new static($this->files, $this->lockDirectory ?? $this->directory, $this->filePermission),
$name,
$seconds,
$owner
);
}

/**
Expand Down Expand Up @@ -364,6 +378,19 @@ public function getDirectory()
return $this->directory;
}

/**
* Set the cache directory where locks should be stored.
*
* @param string|null $lockDirectory
* @return $this
*/
public function setLockDirectory($lockDirectory)
{
$this->lockDirectory = $lockDirectory;

return $this;
}

/**
* Get the cache key prefix.
*
Expand Down

0 comments on commit 7aab67d

Please sign in to comment.