Skip to content

Commit

Permalink
🐛 un-/lock handling
Browse files Browse the repository at this point in the history
  • Loading branch information
bnomei committed Aug 14, 2024
1 parent c4e63cd commit 2316ee5
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 26 deletions.
6 changes: 3 additions & 3 deletions classes/Nitro.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ public function dir(): DirInventory
return $this->dirInventory;
}

public function cache(): SingleFileCache
public function cache(array $options = []): SingleFileCache
{
if (! $this->singleFileCache) {
$this->singleFileCache = new SingleFileCache($this->options);
if (! $this->singleFileCache || ! empty($options)) {
$this->singleFileCache = new SingleFileCache($this->options + $options);
}

return $this->singleFileCache;
Expand Down
9 changes: 7 additions & 2 deletions classes/Nitro/SingleFileCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ public function __construct(array $options = [])
'debug' => option('debug'),
], $options);

$this->atomic();

$data = F::exists($this->file()) ? F::read($this->file()) : null;
$data = $data ? json_decode($data, true) : null;
if (is_array($data)) {
Expand All @@ -40,8 +42,6 @@ public function __construct(array $options = [])
if ($this->options['auto-clean-cache']) {
$this->clean();
}

$this->atomic();
}

public function __destruct()
Expand Down Expand Up @@ -174,6 +174,11 @@ protected function file(?string $key = null): string

public function write(bool $lock = true): bool
{
// if is atomic but has no file, don't write
if ($this->options['atomic'] && ! F::exists($this->file().'.lock')) {
return false;
}

$this->unlock();

if ($this->isDirty === 0) {
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-nitro",
"type": "kirby-plugin",
"version": "2.0.0",
"version": "2.0.1",
"description": "Nitro speeds up the loading of content in your Kirby project.",
"license": "MIT",
"authors": [
Expand Down
29 changes: 14 additions & 15 deletions composer.lock

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

2 changes: 1 addition & 1 deletion index.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ function nitro(): \Bnomei\Nitro
'command' => static function ($cli): void {

$cli->out('🛼 Unlocking...');
$success = nitro()->cache()->unlock();
$success = nitro()->cache(['atomic' => false, 'auto-clean-cache' => false])->unlock();
$success ? $cli->success('🔓 Unlocked.') : $cli->error('❌ Failed.');

// the flush is necessary as the current instance might not have valid data anymore
Expand Down
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-nitro',
'pretty_version' => '2.0.0',
'version' => '2.0.0.0',
'pretty_version' => '2.0.1',
'version' => '2.0.1.0',
'reference' => null,
'type' => 'kirby-plugin',
'install_path' => __DIR__ . '/../../',
Expand All @@ -11,8 +11,8 @@
),
'versions' => array(
'bnomei/kirby-nitro' => array(
'pretty_version' => '2.0.0',
'version' => '2.0.0.0',
'pretty_version' => '2.0.1',
'version' => '2.0.1.0',
'reference' => null,
'type' => 'kirby-plugin',
'install_path' => __DIR__ . '/../../',
Expand Down

0 comments on commit 2316ee5

Please sign in to comment.