Skip to content

Commit 708a4c3

Browse files
committed
Clear page cache for currently selected site in admin
1 parent a73c426 commit 708a4c3

File tree

3 files changed

+25
-16
lines changed

3 files changed

+25
-16
lines changed

admin/controller/tools/cache.php

+15-9
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
class Cache extends Base {
3030
private function clear($fn) {
31-
if (CacheManager :: $fn()) {
31+
if ($fn()) {
3232
$this->view->success[] = __('Cache deleted!');
3333
} else {
3434
$this->view->errors[] = __('Error purging cache!');
@@ -38,31 +38,31 @@ private function clear($fn) {
3838
}
3939

4040
function delete() {
41-
return $this->clear('delete');
41+
return $this->clear(fn () => CacheManager :: delete());
4242
}
4343

4444
function template() {
45-
return $this->clear('clearCompiledFiles');
45+
return $this->clear(fn () => CacheManager :: clearCompiledFiles());
4646
}
4747

4848
function page() {
49-
return $this->clear('clearPageCache');
49+
return $this->clear(fn () => CacheManager :: clearPageCache($this->global['site_url']));
5050
}
5151

5252
function database() {
53-
return $this->clear('clearObjectCache');
53+
return $this->clear(fn () => CacheManager :: clearObjectCache());
5454
}
5555

5656
function asset() {
57-
return $this->clear('clearFrontend');
57+
return $this->clear(fn () => CacheManager :: clearFrontend());
5858
}
5959

6060
function model() {
61-
return $this->clear('clearModelCache');
61+
return $this->clear(fn () => CacheManager :: clearModelCache());
6262
}
6363

6464
function image() {
65-
return $this->clear('clearImageCache');
65+
return $this->clear(fn () => CacheManager :: clearImageCache());
6666
}
6767

6868
function stale() {
@@ -78,10 +78,16 @@ function index() {
7878
'/storage/compiled_templates' => DIR_COMPILED_TEMPLATES,
7979
];
8080

81+
$unwritable = [];
82+
8183
foreach ($folders as $folder => $path) {
8284
if (! is_writable($path)) {
83-
$this->view->info[] = sprintf('Folder is not writable, clear cache might not work for this layer, make sure that <b>%s</b> is writable by php', $folder);
85+
$unwritable[] = $folder;
8486
}
8587
}
88+
89+
if ($unwritable) {
90+
$this->view->info[] = sprintf('Folders <b>%s</b> are not writable, clear cache might not work for these layers', implode(', ', $unwritable));
91+
}
8692
}
8793
}

system/cache-manager.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ public static function clearObjectCache($namespace = '', $key = '') {
104104
return $cacheDriver->delete($namespace, $key);
105105
}
106106

107-
public static function clearPageCache($namespace = '') {
108-
$pageCache = PageCache::getInstance();
107+
public static function clearPageCache($host = null, $namespace = '') {
108+
$pageCache = new PageCache($host);
109109

110110
return $pageCache->purge($namespace);
111111
}

system/page-cache.php

+8-5
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,17 @@ static function getInstance() {
5454
return self :: $instance;
5555
}
5656

57-
function __construct() {
58-
$this->cacheFolder = $this->cacheFolder();
57+
function __construct($host = null) {
58+
$this->cacheFolder = $this->cacheFolder($host);
5959
$this->fileName = $this->fileName();
6060
//$this->canSaveCache = $this->canSaveCache();
6161
}
6262

63-
function cacheFolder() {
64-
return DIR_PUBLIC . self :: CACHE_DIR . ($_SERVER['HTTP_HOST'] ?? 'default');
63+
function cacheFolder($host) {
64+
$host = $host ?? $_SERVER['HTTP_HOST'] ?? '';
65+
$hostWp = substr($host, 0, strpos($host, ':') ?: null);
66+
67+
return DIR_PUBLIC . self :: CACHE_DIR . ($hostWp ?? 'default');
6568
}
6669

6770
function fileName() {
@@ -263,7 +266,7 @@ function purge($path = '/') {
263266
if (! @rmdir($file)) {
264267
clearstatcache(false, $file);
265268
}
266-
*/
269+
*/
267270
}
268271
}
269272
}

0 commit comments

Comments
 (0)