Skip to content

Commit 8781452

Browse files
committed
fixed cache
Signed-off-by: Bruno Meilick <[email protected]>
1 parent 211b532 commit 8781452

File tree

4 files changed

+17
-9
lines changed

4 files changed

+17
-9
lines changed

classes/fingerprint.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,16 +64,17 @@ public static function process($file)
6464
kirby()->cache('bnomei.fingerprint')->flush();
6565
}
6666

67-
$lookup = kirby()->cache('bnomei.fingerprint')->get('lookup');
67+
$cacheWithVersion = 'lookup' . str_replace('.','', kirby()->plugin('bnomei/fingerprint')->version());
68+
$lookup = kirby()->cache('bnomei.fingerprint')->get($cacheWithVersion);
6869
if (!$lookup) {
6970
$lookup = [];
7071
$needsPush = true;
7172
}
7273
if (is_a($file, 'Kirby\CMS\File')) {
73-
$key = $file->id();
74-
$root = $file->root();
74+
$key = (string)$file->id();
75+
$root = (string)$file->root();
7576
$mod = \filemtime($root);
76-
$url = $file->url();
77+
$url = (string)$file->url();
7778
} elseif (!\Kirby\Toolkit\V::url($file)) {
7879
$key = ltrim($file, '/');
7980
$root = kirby()->roots()->index() . DIRECTORY_SEPARATOR . $key;
@@ -89,6 +90,8 @@ public static function process($file)
8990
if ($mod && $lookup[$key]['modified'] < $mod) {
9091
$needsPush = true;
9192
}
93+
} else {
94+
$needsPush = true;
9295
}
9396

9497
if ($needsPush) {
@@ -102,7 +105,8 @@ public static function process($file)
102105
$lookup[$key]['integrity'] = static::sriFile($file);
103106
$lookup[$key]['hash'] = static::hashFile($file);
104107
}
105-
kirby()->cache('bnomei.fingerprint')->set('lookup', $lookup);
108+
109+
kirby()->cache('bnomei.fingerprint')->set($cacheWithVersion, $lookup);
106110
}
107111

108112
return \Kirby\Toolkit\A::get($lookup, $key);

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-fingerprint",
33
"type": "plugin",
4-
"version": "2.1.0",
4+
"version": "2.2.0",
55
"description": "File Method and css/js helper to add cachbusting hash and optional Subresource Integrity to file",
66
"license": "MIT",
77
"autoload": {

composer.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,13 @@
1212
\Kirby\Toolkit\F::name($fileroot),
1313
\Kirby\Toolkit\F::extension($fileroot) . '?v=' . \filemtime($fileroot)
1414
]);
15-
$dirname = \dirname($fileroot);
1615

17-
$url = ($dirname === '.') ? $filename : ($dirname . '/' . $filename);
16+
if(is_a($file, 'Kirby\Cms\File')) {
17+
$url = str_replace($file->filename(), $filename, $file->url());
18+
} else {
19+
$dirname = str_replace(kirby()->roots()->index(), '', \dirname($fileroot));
20+
$url = ($dirname === '.') ? $filename : ($dirname . '/' . $filename);
21+
}
1822
} else {
1923
$url = $file;
2024
}

0 commit comments

Comments
 (0)