Skip to content

Commit

Permalink
✨ php8.0 support (not just php8.1+). thx @psntr
Browse files Browse the repository at this point in the history
⬆️ upgraded dependencies

closes #16

Signed-off-by: bnomei <b@bnomei.com>
  • Loading branch information
bnomei committed Feb 1, 2023
1 parent cd3a20c commit eb08999
Show file tree
Hide file tree
Showing 78 changed files with 830 additions and 1,927 deletions.
19 changes: 10 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -416,15 +416,16 @@ $boostedCount = site()->boost();

## Settings

| bnomei.boost. | Default | Description |
|---------------------------|----------|--------------------------------------------------------------------------------------------------------------------------|
| expire | `0` | expire in minutes for all caches created |
| read | `true` | read from cache |
| write | `true` | write to cache |
| drafts | `true` | index drafts |
| patch.files | `true` | monkey patch Files Class to do content caching |
| fileModifiedCheck | `false` | expects file to not be altered outside of kirby | |
| helper | `true` | allow usage of boost() helper |
| bnomei.boost. | Default | Description |
|-------------------|--------------|-------------------------------------------------|
| hashalgo | `xxh3,crc32` | used hash algorithm php8.1+/php8.0 |
| expire | `0` | expire in minutes for all caches created |
| read | `true` | read from cache |
| write | `true` | write to cache |
| drafts | `true` | index drafts |
| patch.files | `true` | monkey patch Files Class to do content caching |
| fileModifiedCheck | `false` | expects file to not be altered outside of kirby | |
| helper | `true` | allow usage of boost() helper |

## External changes to content files

Expand Down
8 changes: 4 additions & 4 deletions classes/Bolt.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,14 @@ public function lookup(string $id, bool $cache = true): ?Page
{
$lookup = A::get(static::$idToPage, $id);
if (!$lookup && $cache && static::cache()) {
if ($diruri = static::cache()->get('bolt/' . hash('xxh3', $id))) {
if ($diruri = static::cache()->get('bolt/' . hash(BoostCache::hashalgo(), $id))) {
// bolt will ignore caches with invalid paths and update them automatically
// it does not need to be flushed ever
if ($page = $this->findByID($diruri, false)) {
$this->pushLookup($id, $page);
$lookup = $page;
} else {
static::cache()->remove('bolt/' . hash('xxh3', $id));
static::cache()->remove('bolt/' . hash(BoostCache::hashalgo(), $id));
}
}
}
Expand All @@ -98,8 +98,8 @@ public function pushLookup(string $id, Page $page): void

// only update if necessary
$diruri = $page->diruri();
if ($diruri !== static::cache()->get('bolt/' . hash('xxh3', $id))) {
static::cache()->set(hash('xxh3', $id) . '-bolt', $diruri, option('bnomei.boost.expire'));
if ($diruri !== static::cache()->get('bolt/' . hash(BoostCache::hashalgo(), $id))) {
static::cache()->set(hash(BoostCache::hashalgo(), $id) . '-bolt', $diruri, option('bnomei.boost.expire'));
}
}

Expand Down
10 changes: 9 additions & 1 deletion classes/BoostCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ public static function endTransaction()
}
}

public static function hashalgo() {
$algos = explode(',', option('bnomei.boost.hashalgo'));
if (version_compare(PHP_VERSION, '8.1.0') >= 0) {
return $algos[0];
}
return $algos[1];
}

public static function modified($model): ?int
{
if ($model instanceof \Kirby\Cms\Page ||
Expand All @@ -59,7 +67,7 @@ public static function modified($model): ?int
} elseif ($model instanceof \Kirby\Cms\Site) {
return filemtime($model->contentFile());
} elseif (is_string($model)) {
$key = hash('xxh3', $model);
$key = hash(BoostCache::hashalgo(), $model);
$languageCode = kirby()->languages()->count() ? kirby()->language()->code() : null;
if ($languageCode) {
$key = $key . '-' . $languageCode;
Expand Down
2 changes: 1 addition & 1 deletion classes/ModelHasBoost.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function isContentBoosted(string $languageCode = null): bool

public function contentBoostedKey(string $languageCode = null): string
{
$key = hash('xxh3', $this->id()); // can not use UUID since content not loaded yet
$key = hash(BoostCache::hashalgo(), $this->id()); // can not use UUID since content not loaded yet
if (! $languageCode) {
$languageCode = kirby()->languages()->count() ? kirby()->language()->code() : null;
}
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "bnomei/kirby3-boost",
"type": "kirby-plugin",
"version": "2.1.0",
"version": "2.2.0",
"description": "Boost the speed of Kirby by having content files of files/pages/users cached, with fast lookup based on uuid.",
"license": "MIT",
"authors": [
Expand Down Expand Up @@ -45,7 +45,7 @@
}
},
"require": {
"php": ">=8.1.0",
"php": ">=8.0.0",
"bnomei/autoloader-for-kirby": "^1.2",
"getkirby/composer-installer": "^1.2"
},
Expand Down

0 comments on commit eb08999

Please sign in to comment.