Skip to content
This repository was archived by the owner on May 18, 2025. It is now read-only.

Commit ee60864

Browse files
committed
🚑 multi-language setups did not work, modified check edge cases
✨ read and write options
1 parent 78dcbfb commit ee60864

File tree

13 files changed

+68
-17
lines changed

13 files changed

+68
-17
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,8 @@ echo $page->tinyurl(); // https://devkit.bnomei.com/x/8j5g64hh
318318
|---------------------------|----------------|---------------------------|
319319
| fieldname | `'boostid'` | change name of loaded field |
320320
| expire | `0` | expire in minutes for all caches created |
321+
| read | `true` | read from cache |
322+
| write | `true` | write to cache |
321323
| fileModifiedCheck | `false` | expects file to not be altered outside of kirby |
322324
| index.generator | callback | the uuid genertor |
323325
| tinyurl.url | callback | returning `site()->url()`. Use htaccess on that domain to redirect `RewriteRule (.*) http://www.bnomei.com/x/$1 [R=301]` |

classes/BoostIndex.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function __construct()
2929

3030
$cache = $this->cache();
3131
if ($cache && method_exists($cache, 'register_shutdown_function')) {
32-
$cache->register_shutdown_function(function() {
32+
$cache->register_shutdown_function(function () {
3333
$this->write();
3434
});
3535
}
@@ -87,7 +87,7 @@ public function index(bool $force = false, ?Page $target = null): int
8787
// only search until target is found
8888
if ($target && $target->id() === $page->id()) {
8989
$this->write();
90-
break;
90+
break;
9191
}
9292
}
9393
return $count;

classes/PageHasBoost.php

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,11 @@ public function forceNewBoostId(bool $overwrite = false, ?string $id = null)
6767
public function contentBoostedKey(string $languageCode = null): string
6868
{
6969
$key = strval(crc32($this->id()));
70-
if (!$languageCode) {
70+
if (! $languageCode) {
7171
$languageCode = kirby()->languages()->count() ? kirby()->language()->code() : null;
72-
if ($languageCode) {
73-
$key = $key . '-' . $languageCode;
74-
}
72+
}
73+
if ($languageCode) {
74+
$key = $key . '-' . $languageCode;
7575
}
7676

7777
return $key;
@@ -84,14 +84,20 @@ public function isContentCacheExpiredByModified(string $languageCode = null): bo
8484
return true;
8585
}
8686

87-
$modified = $this->modified();
8887
$modifiedCache = $cache->get(
8988
$this->contentBoostedKey($languageCode).'-modified',
9089
null
9190
);
9291
if (!$modifiedCache) {
9392
return true;
9493
}
94+
95+
$modified = $this->modified();
96+
// in rare case the file does not exist or is not readable
97+
if ($modified === false) {
98+
return true;
99+
}
100+
// otherwise compare
95101
if ($modifiedCache && intval($modifiedCache) < intval($modified)) {
96102
return true;
97103
}
@@ -116,7 +122,7 @@ public function readContentCache(string $languageCode = null): ?array
116122
public function readContent(string $languageCode = null): array
117123
{
118124
// read from boostedCache if exists
119-
$data = option('debug') ? null : $this->readContentCache($languageCode);
125+
$data = option('bnomei.boost.read') === false || option('debug') ? null : $this->readContentCache($languageCode);
120126

121127
// read from file and update boostedCache
122128
if (! $data) {
@@ -132,13 +138,20 @@ public function readContent(string $languageCode = null): array
132138
public function writeContentCache(?array $data = null, string $languageCode = null): bool
133139
{
134140
$cache = BoostCache::singleton();
135-
if (! $cache) {
141+
if (! $cache || option('bnomei.boost.write') === false) {
136142
return true;
137143
}
138144

145+
$modified = $this->modified();
146+
147+
// in rare case file does not exists or is not readable
148+
if ($modified === false) {
149+
return false; // try again another time
150+
}
151+
139152
$cache->set(
140153
$this->contentBoostedKey($languageCode) . '-modified',
141-
$this->modified(),
154+
$modified,
142155
option('bnomei.boost.expire')
143156
);
144157

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "bnomei/kirby3-boost",
33
"type": "kirby-plugin",
4-
"version": "1.6.5",
4+
"version": "1.6.6",
55
"description": "Boost the speed of Kirby by having content files of pages cached, with automatic unique ID, fast lookup and Tiny-URL.",
66
"license": "MIT",
77
"authors": [

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ services:
77
- 8000:80
88
environment:
99
WEB_DOCUMENT_ROOT: /app/tests/
10-
WEB_ALIAS_DOMAIN: boost.test
10+
WEB_ALIAS_DOMAIN: localhost
1111
volumes:
1212
- .:/app:rw

index.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ function siteIndexFilterByBoostID(string $id): ?\Kirby\Cms\Page
4343
'fieldname' => 'boostid', // autoid
4444
'expire' => 0,
4545
'fileModifiedCheck' => false, // expects file to not be altered outside of kirby
46+
'read' => true, // read from cache
47+
'write' => true, // write to cache
4648
'index' => [
4749
'generator' => function (?string $seed = null) {
4850
// override with custom callback if needed
File renamed without changes.

tests/content/site.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

tests/site/config/config.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@
22

33
return [
44
'debug' => false, // must be off for cache to stick
5+
6+
'languages' => true,
57
];

tests/site/languages/de.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
return [
4+
'code' => 'de',
5+
'default' => false,
6+
'direction' => 'ltr',
7+
'locale' => [
8+
'LC_ALL' => 'de_DE'
9+
],
10+
'name' => 'German',
11+
'translations' => [
12+
13+
],
14+
'url' => null
15+
];

0 commit comments

Comments
 (0)