Skip to content

Commit

Permalink
Extend the cache driver within register
Browse files Browse the repository at this point in the history
As per laravel/docs#6598
Closes #1721
  • Loading branch information
jasonvarga committed Dec 16, 2020
1 parent ef1ec33 commit 7a32adc
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions src/Providers/CacheServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,23 @@

class CacheServiceProvider extends ServiceProvider
{
/**
* Register any application services.
*
* @return void
*/
public function register()
{
$this->extendFileStore();
}

/**
* Bootstrap services.
*
* @return void
*/
public function boot()
{
$this->extendFileStore();
$this->macroRememberWithExpiration();
}

Expand All @@ -27,17 +36,19 @@ public function boot()
*/
private function extendFileStore()
{
Cache::extend('statamic', function () {
return Cache::repository(new FileStore(
$this->app['files'],
$this->app['config']['cache.stores.file']['path']
));
});
$this->app->booting(function () {
Cache::extend('statamic', function () {
return Cache::repository(new FileStore(
$this->app['files'],
$this->app['config']['cache.stores.file']['path']
));
});

if (config('cache.default') === 'file') {
config(['cache.stores.statamic' => ['driver' => 'statamic']]);
config(['cache.default' => 'statamic']);
}
if (config('cache.default') === 'file') {
config(['cache.stores.statamic' => ['driver' => 'statamic']]);
config(['cache.default' => 'statamic']);
}
});
}

/**
Expand Down

0 comments on commit 7a32adc

Please sign in to comment.