Skip to content

Commit

Permalink
⚡ even better caching (yaml)
Browse files Browse the repository at this point in the history
  • Loading branch information
bnomei committed Mar 22, 2024
1 parent 151b5c4 commit 25fcdc0
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 26 deletions.
20 changes: 15 additions & 5 deletions classes/Blueprints/BlueprintCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,10 @@ public static function get(string $key, $default = null, $expire = null): ?array
$file = static::cacheFile($key);

if ($file && static::exists($key, $expire)) {
return Json::read($file);
$data = Json::read($file);
//\Kirby\Cms\Blueprint::$loaded[$key] = $data;

return $data;
}

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

/*
public static function preloadCachedBlueprints(): void
public static function preloadCachedBlueprints(): int
{
$blueprints = [];
foreach (Dir::dirs(static::cacheDir(), [], true) as $dir) {
foreach (Dir::files($dir, [], true) as $file) {
if (! \Kirby\Toolkit\Str::endsWith($file, '.cache')) {
continue;
}
$key = str_replace([static::cacheDir().'/', '.cache'], ['', ''], $file);
/* this check would decrease performance
if (\Kirby\Toolkit\A::get(\Kirby\Cms\Blueprint::$loaded, $key)) {
continue;
}*/
$blueprint = Json::read($file);
\Kirby\Cms\Blueprint::$loaded[$key] = $blueprint;
//\Kirby\Cms\Blueprint::$loaded[$key] = $blueprint;
$blueprints[$key] = $blueprint;
}
}
// ray('preloaded', \Kirby\Cms\Blueprint::$loaded);
kirby()->extend(
['blueprints' => $blueprints],
);

return count(\Kirby\Cms\Blueprint::$loaded);
}
*/
}
2 changes: 1 addition & 1 deletion classes/Blueprints/Schema/Section.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
* @method self theme(string $text)
* // PAGES
* @method self create(bool|array $create)
* @method self status(string $status='all')
* @method self status(string $status = 'all')
* @method self templates(array $templates)
* // STATS
* @method self reports(string|array $reports)
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "bnomei/kirby-blueprints",
"type": "kirby-plugin",
"version": "4.4.1",
"version": "4.4.2",
"license": "MIT",
"homepage": "https://github.com/bnomei/kirby3-blueprints",
"description": "PHP Class-based Blueprints for Kirby CMS for better type safety and code completion",
Expand Down
30 changes: 15 additions & 15 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
// and use it on next request
\Bnomei\Blueprints\BlueprintCache::rememberCacheDir();
\Bnomei\Blueprints\Blueprint::loadPluginsAfter();
\Bnomei\Blueprints\BlueprintCache::preloadCachedBlueprints();
},
],
]);
8 changes: 4 additions & 4 deletions vendor/composer/installed.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php return array(
'root' => array(
'name' => 'bnomei/kirby-blueprints',
'pretty_version' => '4.4.1',
'version' => '4.4.1.0',
'pretty_version' => '4.4.2',
'version' => '4.4.2.0',
'reference' => null,
'type' => 'kirby-plugin',
'install_path' => __DIR__ . '/../../',
Expand All @@ -11,8 +11,8 @@
),
'versions' => array(
'bnomei/kirby-blueprints' => array(
'pretty_version' => '4.4.1',
'version' => '4.4.1.0',
'pretty_version' => '4.4.2',
'version' => '4.4.2.0',
'reference' => null,
'type' => 'kirby-plugin',
'install_path' => __DIR__ . '/../../',
Expand Down

0 comments on commit 25fcdc0

Please sign in to comment.