Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[4.x] Allow a custom static caching url store to be specified #9405

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions config/static_caching.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
'full' => [
'driver' => 'file',
'path' => public_path('static'),
'cache_path' => null,
ryanmitchell marked this conversation as resolved.
Show resolved Hide resolved
'lock_hold_length' => 0,
],

Expand Down
5 changes: 5 additions & 0 deletions src/StaticCaching/Cachers/FileCacher.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Contracts\Cache\Repository;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\File as LaravelFile;
use Illuminate\Support\Facades\Log;
use Statamic\Events\UrlInvalidated;
use Statamic\Facades\File;
Expand Down Expand Up @@ -103,6 +104,10 @@ public function flush()
$this->writer->flush($path);
}

if ($path = config('statamic.static_caching.strategies.full.cache_path')) {
LaravelFile::deleteDirectory($path);
}

$this->flushUrls();
}

Expand Down
11 changes: 10 additions & 1 deletion src/StaticCaching/StaticCacheManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Cache\Repository;
use Illuminate\Support\Facades\Cache;
use Statamic\Extensions\FileStore;
use Statamic\Facades\Site;
use Statamic\StaticCaching\Cachers\ApplicationCacher;
use Statamic\StaticCaching\Cachers\FileCacher;
Expand All @@ -30,7 +31,15 @@ public function createNullDriver()

public function createFileDriver(array $config)
{
return new FileCacher(new Writer, $this->app[Repository::class], $config);
$customCacheStore = null;

if ($path = config('statamic.static_caching.strategies.full.cache_path')) {
$customCacheStore = app('cache')->repository(
(new FileStore($this->app['files'], $path))
);
}

return new FileCacher(new Writer, $customCacheStore ?? $this->app[Repository::class], $config);
}

public function createApplicationDriver(array $config)
Expand Down
Loading