Skip to content

Commit

Permalink
Cached Configuration (#14)
Browse files Browse the repository at this point in the history
* fix(cache): cached configuration

* Fixing the cached configuration so update works
* Adding in a check to see if the framework is installed before registering the blade composer

* fix(husky): coverage

Adding in the code coverage flag
  • Loading branch information
awjudd authored Nov 18, 2021
1 parent 4485e5e commit 4c34894
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .husky/pre-push
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

./vendor/bin/phpunit --coverage-html ./build
XDEBUG_MODE=coverage ./vendor/bin/phpunit --coverage-html ./build
php coverage-checker.php ./build/clover.xml 95
10 changes: 10 additions & 0 deletions src/Configuration/Providers/ConfigurationServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use GamingEngine\Core\Configuration\Repositories\ConfigurationRepository;
use GamingEngine\Core\Configuration\Repositories\DatabaseConfigurationRepository;
use GamingEngine\Core\Configuration\SiteConfiguration;
use GamingEngine\Core\Core;
use GamingEngine\Core\Framework\Http\View\Composers\ConfigurationViewComposer;
use Illuminate\Support\Facades\View;
use Illuminate\Support\ServiceProvider;
Expand Down Expand Up @@ -47,6 +48,15 @@ function () {

public function boot()
{
/**
* @var Core $core
*/
$core = app(Core::class);

if (! $core->installed()) {
return;
}

View::composer('*', ConfigurationViewComposer::class);
}
}
18 changes: 9 additions & 9 deletions src/Configuration/Repositories/CachedConfigurationRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,6 @@ public function account(): AccountConfiguration
);
}

public function site(): SiteConfiguration
{
return $this->cache(
SiteConfiguration::type(),
fn () => $this->configurationRepository->site()
);
}

private function cache(string $category, callable $values)
{
return Cache::rememberForever(
Expand All @@ -52,13 +44,21 @@ private function cacheKey(string $category): string
);
}

public function site(): SiteConfiguration
{
return $this->cache(
SiteConfiguration::type(),
fn () => $this->configurationRepository->site()
);
}

public function update(BaseConfiguration $configuration): BaseConfiguration
{
$response = $this->configurationRepository->update($configuration);

Cache::put(
$this->cacheKey($configuration::type()),
fn () => $response,
$response,
);

return $response;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public function cached_configuration_will_re_cache_the_data_on_update()
$repository = new CachedConfigurationRepository($wrapped);

Cache::shouldReceive('put')
->withArgs(fn ($key, $c) => $configuration === $c())
->withArgs(fn ($key, $c) => $configuration === $c)
->andReturn($configuration);

$wrapped->shouldReceive('update')
Expand Down

0 comments on commit 4c34894

Please sign in to comment.