Skip to content

Commit

Permalink
Clear config cache on bin/console cache:clear
Browse files Browse the repository at this point in the history
  • Loading branch information
I-Valchev committed Jan 22, 2021
1 parent 11f4803 commit 329635c
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/Configuration/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

class Config
{
public const CACHE_KEY = 'config_cache';

/** @var Collection */
protected $data;

Expand Down Expand Up @@ -76,7 +78,7 @@ private function getConfig(): Collection
// Verify if timestamps are unchanged. If not, invalidate cache.
foreach ($timestamps as $filename => $timestamp) {
if (file_exists($filename) === false || filemtime($filename) > $timestamp) {
$this->cache->delete('config_cache');
$this->cache->delete(self::CACHE_KEY);
[$data] = $this->getCache();

// Clear the entire cache in order to re-generate %bolt.requirement.contenttypes%
Expand All @@ -91,7 +93,7 @@ private function getConfig(): Collection

private function getCache(): array
{
return $this->cache->get('config_cache', function () {
return $this->cache->get(self::CACHE_KEY, function () {
return $this->parseConfig();
});
}
Expand Down
25 changes: 25 additions & 0 deletions src/Event/ConfigCacheClearer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

declare(strict_types=1);

namespace Bolt\Event;

use Bolt\Configuration\Config;
use Symfony\Component\HttpKernel\CacheClearer\CacheClearerInterface;
use Symfony\Contracts\Cache\CacheInterface;

class ConfigCacheClearer implements CacheClearerInterface
{
/** @var CacheInterface */
private $cache;

public function __construct(CacheInterface $cache)
{
$this->cache = $cache;
}

public function clear(string $cacheDir): void
{
$this->cache->delete(Config::CACHE_KEY);
}
}

0 comments on commit 329635c

Please sign in to comment.