Skip to content

Commit 25fcdc0

Browse files
committed
⚡ even better caching (yaml)
1 parent 151b5c4 commit 25fcdc0

File tree

6 files changed

+37
-26
lines changed

6 files changed

+37
-26
lines changed

classes/Blueprints/BlueprintCache.php

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,10 @@ public static function get(string $key, $default = null, $expire = null): ?array
7070
$file = static::cacheFile($key);
7171

7272
if ($file && static::exists($key, $expire)) {
73-
return Json::read($file);
73+
$data = Json::read($file);
74+
//\Kirby\Cms\Blueprint::$loaded[$key] = $data;
75+
76+
return $data;
7477
}
7578

7679
return $default;
@@ -88,22 +91,29 @@ public static function getKey(): string
8891
return 'bnomei.blueprints.cache.dir';
8992
}
9093

91-
/*
92-
public static function preloadCachedBlueprints(): void
94+
public static function preloadCachedBlueprints(): int
9395
{
96+
$blueprints = [];
9497
foreach (Dir::dirs(static::cacheDir(), [], true) as $dir) {
9598
foreach (Dir::files($dir, [], true) as $file) {
9699
if (! \Kirby\Toolkit\Str::endsWith($file, '.cache')) {
97100
continue;
98101
}
99102
$key = str_replace([static::cacheDir().'/', '.cache'], ['', ''], $file);
103+
/* this check would decrease performance
104+
if (\Kirby\Toolkit\A::get(\Kirby\Cms\Blueprint::$loaded, $key)) {
105+
continue;
106+
}*/
100107
$blueprint = Json::read($file);
101-
\Kirby\Cms\Blueprint::$loaded[$key] = $blueprint;
108+
//\Kirby\Cms\Blueprint::$loaded[$key] = $blueprint;
109+
$blueprints[$key] = $blueprint;
102110
}
103111
}
104112
// ray('preloaded', \Kirby\Cms\Blueprint::$loaded);
113+
kirby()->extend(
114+
['blueprints' => $blueprints],
115+
);
105116

106117
return count(\Kirby\Cms\Blueprint::$loaded);
107118
}
108-
*/
109119
}

classes/Blueprints/Schema/Section.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
* @method self theme(string $text)
3636
* // PAGES
3737
* @method self create(bool|array $create)
38-
* @method self status(string $status='all')
38+
* @method self status(string $status = 'all')
3939
* @method self templates(array $templates)
4040
* // STATS
4141
* @method self reports(string|array $reports)

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "bnomei/kirby-blueprints",
33
"type": "kirby-plugin",
4-
"version": "4.4.1",
4+
"version": "4.4.2",
55
"license": "MIT",
66
"homepage": "https://github.com/bnomei/kirby3-blueprints",
77
"description": "PHP Class-based Blueprints for Kirby CMS for better type safety and code completion",

composer.lock

Lines changed: 15 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

index.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
// and use it on next request
1616
\Bnomei\Blueprints\BlueprintCache::rememberCacheDir();
1717
\Bnomei\Blueprints\Blueprint::loadPluginsAfter();
18+
\Bnomei\Blueprints\BlueprintCache::preloadCachedBlueprints();
1819
},
1920
],
2021
]);

vendor/composer/installed.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?php return array(
22
'root' => array(
33
'name' => 'bnomei/kirby-blueprints',
4-
'pretty_version' => '4.4.1',
5-
'version' => '4.4.1.0',
4+
'pretty_version' => '4.4.2',
5+
'version' => '4.4.2.0',
66
'reference' => null,
77
'type' => 'kirby-plugin',
88
'install_path' => __DIR__ . '/../../',
@@ -11,8 +11,8 @@
1111
),
1212
'versions' => array(
1313
'bnomei/kirby-blueprints' => array(
14-
'pretty_version' => '4.4.1',
15-
'version' => '4.4.1.0',
14+
'pretty_version' => '4.4.2',
15+
'version' => '4.4.2.0',
1616
'reference' => null,
1717
'type' => 'kirby-plugin',
1818
'install_path' => __DIR__ . '/../../',

0 commit comments

Comments
 (0)