Skip to content

Commit a540a7a

Browse files
committed
WEB: Properly clear cache after data update
1 parent 719827c commit a540a7a

File tree

5 files changed

+21
-6
lines changed

5 files changed

+21
-6
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,7 @@
3535

3636
# Others
3737
public_html/frs
38+
39+
# Clear cache instruction
40+
.clear-cache
41+
.no-cache

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ respectively.
5252

5353
## Deployment
5454

55-
To deploy changes to the official ScummVM website, simply go to the website admin page and click the "ScummVM.org
55+
To deploy changes to the official ScummVM website, simply go to the website admin page and click the "ScummVM.org
5656
manual site update" link.
5757

5858
## Updating data
@@ -62,6 +62,11 @@ run `composer update-data` note that this will run automatically on site update
6262
but is encouraged for you to do manually to keep track on who's updating the
6363
data.
6464

65+
## Disabling cache
66+
67+
During development, you can disable data caching by creating a file called
68+
`.no-cache` in the root folder.
69+
6570
## Contributing
6671

6772
Similar to ScummVM, please use the appropriate project name when contributing:

composer.json

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,8 @@
6969
"lint": [
7070
"phpcbf --standard=psr2 ./include"
7171
],
72-
"flush-cache": [
73-
"redis-cli -n 8 flushdb"
74-
],
7572
"update-data": [
76-
"php include/DataUtils.php",
77-
"@flush-cache"
73+
"php include/DataUtils.php"
7874
],
7975
"scss": [
8076
"pscss -f compressed ./scss/main_ltr.scss > ./public_html/css/main_ltr.css",

include/DataUtils.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ public function getAllData()
6969
$outFile = DIR_DATA . "/" . DEFAULT_LOCALE . "/$name.yaml";
7070
echo("Writing $name data to $outFile\n");
7171
\file_put_contents($outFile, $yaml);
72+
\file_put_contents('.clear-cache', '');
7273
}
7374
}
7475
}

include/Models/BasicModel.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ public function __construct()
2626
// Fallback to files based cache
2727
self::$cache = new Psr16Adapter('files');
2828
}
29+
30+
if (\file_exists(DIR_BASE . '/.clear-cache')) {
31+
self::$cache->clear();
32+
unlink(DIR_BASE . '/.clear-cache');
33+
}
2934
}
3035
}
3136

@@ -58,6 +63,10 @@ protected function saveToCache($data, $key = '')
5863

5964
protected function getFromCache($key = '')
6065
{
66+
if (\file_exists(DIR_BASE . '/.no-cache')) {
67+
return null;
68+
}
69+
6170
if ($key) {
6271
$key = "_$key";
6372
}

0 commit comments

Comments
 (0)