Skip to content

Commit 27d90b2

Browse files
authored
Merge pull request #1941 from alissn/DeleteCache
Delete cache of module_status.json
2 parents f183d64 + f1badf4 commit 27d90b2

File tree

4 files changed

+2
-80
lines changed

4 files changed

+2
-80
lines changed

config/config.php

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -247,21 +247,6 @@
247247
'composer-output' => false,
248248
],
249249

250-
/*
251-
|--------------------------------------------------------------------------
252-
| Caching
253-
|--------------------------------------------------------------------------
254-
|
255-
| Here is the config for setting up the caching feature.
256-
|
257-
*/
258-
'cache' => [
259-
'enabled' => env('MODULES_CACHE_ENABLED', false),
260-
'driver' => env('MODULES_CACHE_DRIVER', 'file'),
261-
'key' => env('MODULES_CACHE_KEY', 'laravel-modules'),
262-
'lifetime' => env('MODULES_CACHE_LIFETIME', 60),
263-
],
264-
265250
/*
266251
|--------------------------------------------------------------------------
267252
| Choose what laravel-modules will register as custom namespaces.
@@ -290,8 +275,6 @@
290275
'file' => [
291276
'class' => FileActivator::class,
292277
'statuses-file' => base_path('modules_statuses.json'),
293-
'cache-key' => 'activator.installed',
294-
'cache-lifetime' => 604800,
295278
],
296279
],
297280

src/Activators/FileActivator.php

Lines changed: 2 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,6 @@
1212

1313
class FileActivator implements ActivatorInterface
1414
{
15-
/**
16-
* Laravel cache instance
17-
*
18-
* @var CacheManager
19-
*/
20-
private $cache;
21-
2215
/**
2316
* Laravel Filesystem instance
2417
*
@@ -33,16 +26,6 @@ class FileActivator implements ActivatorInterface
3326
*/
3427
private $config;
3528

36-
/**
37-
* @var string
38-
*/
39-
private $cacheKey;
40-
41-
/**
42-
* @var string
43-
*/
44-
private $cacheLifetime;
45-
4629
/**
4730
* Array of modules activation statuses
4831
*
@@ -59,13 +42,10 @@ class FileActivator implements ActivatorInterface
5942

6043
public function __construct(Container $app)
6144
{
62-
$this->cache = $app['cache'];
6345
$this->files = $app['files'];
6446
$this->config = $app['config'];
6547
$this->statusesFile = $this->config('statuses-file');
66-
$this->cacheKey = $this->config('cache-key');
67-
$this->cacheLifetime = $this->config('cache-lifetime');
68-
$this->modulesStatuses = $this->getModulesStatuses();
48+
$this->modulesStatuses = $this->readJson();
6949
}
7050

7151
/**
@@ -85,7 +65,6 @@ public function reset(): void
8565
$this->files->delete($this->statusesFile);
8666
}
8767
$this->modulesStatuses = [];
88-
$this->flushCache();
8968
}
9069

9170
/**
@@ -131,7 +110,6 @@ public function setActiveByName(string $name, bool $status): void
131110
{
132111
$this->modulesStatuses[$name] = $status;
133112
$this->writeJson();
134-
$this->flushCache();
135113
}
136114

137115
/**
@@ -144,7 +122,6 @@ public function delete(Module $module): void
144122
}
145123
unset($this->modulesStatuses[$module->getName()]);
146124
$this->writeJson();
147-
$this->flushCache();
148125
}
149126

150127
/**
@@ -166,24 +143,7 @@ private function readJson(): array
166143
return [];
167144
}
168145

169-
return json_decode($this->files->get($this->statusesFile), true);
170-
}
171-
172-
/**
173-
* Get modules statuses, either from the cache or from
174-
* the json statuses file if the cache is disabled.
175-
*
176-
* @throws FileNotFoundException
177-
*/
178-
private function getModulesStatuses(): array
179-
{
180-
if (! $this->config->get('modules.cache.enabled')) {
181-
return $this->readJson();
182-
}
183-
184-
return $this->cache->store($this->config->get('modules.cache.driver'))->remember($this->cacheKey, $this->cacheLifetime, function () {
185-
return $this->readJson();
186-
});
146+
return $this->files->json($this->statusesFile);
187147
}
188148

189149
/**
@@ -195,12 +155,4 @@ private function config(string $key, $default = null)
195155
{
196156
return $this->config->get('modules.activators.file.'.$key, $default);
197157
}
198-
199-
/**
200-
* Flushes the modules activation statuses cache
201-
*/
202-
private function flushCache(): void
203-
{
204-
$this->cache->store($this->config->get('modules.cache.driver'))->forget($this->cacheKey);
205-
}
206158
}

src/Module.php

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,6 @@ public function disable(): void
347347
$this->fireEvent(ModuleEvent::DISABLING);
348348

349349
$this->activator->disable($this);
350-
$this->flushCache();
351350

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

362361
$this->activator->enable($this);
363-
$this->flushCache();
364362

365363
$this->fireEvent(ModuleEvent::ENABLED);
366364
}
@@ -399,13 +397,6 @@ protected function isLoadFilesOnBoot(): bool
399397
! class_exists('\Modules\Core\Foundation\AsgardCms');
400398
}
401399

402-
private function flushCache(): void
403-
{
404-
if (config('modules.cache.enabled')) {
405-
$this->cache->store(config('modules.cache.driver'))->flush();
406-
}
407-
}
408-
409400
/**
410401
* Register a translation file namespace.
411402
*/

src/Traits/CanClearModulesCache.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@ trait CanClearModulesCache
99
*/
1010
public function clearCache()
1111
{
12-
if (config('modules.cache.enabled') === true) {
13-
app('cache')->forget(config('modules.cache.key'));
14-
}
15-
1612
$this->laravel['modules']->resetModules();
1713
}
1814
}

0 commit comments

Comments
 (0)