Skip to content

Commit

Permalink
Merge pull request #1941 from alissn/DeleteCache
Browse files Browse the repository at this point in the history
Delete cache of module_status.json
  • Loading branch information
dcblogdev authored Sep 14, 2024
2 parents f183d64 + f1badf4 commit 27d90b2
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 80 deletions.
17 changes: 0 additions & 17 deletions config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -247,21 +247,6 @@
'composer-output' => false,
],

/*
|--------------------------------------------------------------------------
| Caching
|--------------------------------------------------------------------------
|
| Here is the config for setting up the caching feature.
|
*/
'cache' => [
'enabled' => env('MODULES_CACHE_ENABLED', false),
'driver' => env('MODULES_CACHE_DRIVER', 'file'),
'key' => env('MODULES_CACHE_KEY', 'laravel-modules'),
'lifetime' => env('MODULES_CACHE_LIFETIME', 60),
],

/*
|--------------------------------------------------------------------------
| Choose what laravel-modules will register as custom namespaces.
Expand Down Expand Up @@ -290,8 +275,6 @@
'file' => [
'class' => FileActivator::class,
'statuses-file' => base_path('modules_statuses.json'),
'cache-key' => 'activator.installed',
'cache-lifetime' => 604800,
],
],

Expand Down
52 changes: 2 additions & 50 deletions src/Activators/FileActivator.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,6 @@

class FileActivator implements ActivatorInterface
{
/**
* Laravel cache instance
*
* @var CacheManager
*/
private $cache;

/**
* Laravel Filesystem instance
*
Expand All @@ -33,16 +26,6 @@ class FileActivator implements ActivatorInterface
*/
private $config;

/**
* @var string
*/
private $cacheKey;

/**
* @var string
*/
private $cacheLifetime;

/**
* Array of modules activation statuses
*
Expand All @@ -59,13 +42,10 @@ class FileActivator implements ActivatorInterface

public function __construct(Container $app)
{
$this->cache = $app['cache'];
$this->files = $app['files'];
$this->config = $app['config'];
$this->statusesFile = $this->config('statuses-file');
$this->cacheKey = $this->config('cache-key');
$this->cacheLifetime = $this->config('cache-lifetime');
$this->modulesStatuses = $this->getModulesStatuses();
$this->modulesStatuses = $this->readJson();
}

/**
Expand All @@ -85,7 +65,6 @@ public function reset(): void
$this->files->delete($this->statusesFile);
}
$this->modulesStatuses = [];
$this->flushCache();
}

/**
Expand Down Expand Up @@ -131,7 +110,6 @@ public function setActiveByName(string $name, bool $status): void
{
$this->modulesStatuses[$name] = $status;
$this->writeJson();
$this->flushCache();
}

/**
Expand All @@ -144,7 +122,6 @@ public function delete(Module $module): void
}
unset($this->modulesStatuses[$module->getName()]);
$this->writeJson();
$this->flushCache();
}

/**
Expand All @@ -166,24 +143,7 @@ private function readJson(): array
return [];
}

return json_decode($this->files->get($this->statusesFile), true);
}

/**
* Get modules statuses, either from the cache or from
* the json statuses file if the cache is disabled.
*
* @throws FileNotFoundException
*/
private function getModulesStatuses(): array
{
if (! $this->config->get('modules.cache.enabled')) {
return $this->readJson();
}

return $this->cache->store($this->config->get('modules.cache.driver'))->remember($this->cacheKey, $this->cacheLifetime, function () {
return $this->readJson();
});
return $this->files->json($this->statusesFile);
}

/**
Expand All @@ -195,12 +155,4 @@ private function config(string $key, $default = null)
{
return $this->config->get('modules.activators.file.'.$key, $default);
}

/**
* Flushes the modules activation statuses cache
*/
private function flushCache(): void
{
$this->cache->store($this->config->get('modules.cache.driver'))->forget($this->cacheKey);
}
}
9 changes: 0 additions & 9 deletions src/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,6 @@ public function disable(): void
$this->fireEvent(ModuleEvent::DISABLING);

$this->activator->disable($this);
$this->flushCache();

$this->fireEvent(ModuleEvent::DISABLED);
}
Expand All @@ -360,7 +359,6 @@ public function enable(): void
$this->fireEvent(ModuleEvent::ENABLING);

$this->activator->enable($this);
$this->flushCache();

$this->fireEvent(ModuleEvent::ENABLED);
}
Expand Down Expand Up @@ -399,13 +397,6 @@ protected function isLoadFilesOnBoot(): bool
! class_exists('\Modules\Core\Foundation\AsgardCms');
}

private function flushCache(): void
{
if (config('modules.cache.enabled')) {
$this->cache->store(config('modules.cache.driver'))->flush();
}
}

/**
* Register a translation file namespace.
*/
Expand Down
4 changes: 0 additions & 4 deletions src/Traits/CanClearModulesCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ trait CanClearModulesCache
*/
public function clearCache()
{
if (config('modules.cache.enabled') === true) {
app('cache')->forget(config('modules.cache.key'));
}

$this->laravel['modules']->resetModules();
}
}

0 comments on commit 27d90b2

Please sign in to comment.