Skip to content

Commit 40070ab

Browse files
committed
SQLiteJournal: lazy initialization
1 parent a3e0f71 commit 40070ab

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/Caching/Storages/SQLiteJournal.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
*/
1717
class SQLiteJournal extends Nette\Object implements IJournal
1818
{
19+
/** @string */
20+
private $path;
21+
1922
/** @var \PDO */
2023
private $pdo;
2124

@@ -28,8 +31,13 @@ public function __construct($path)
2831
if (!extension_loaded('pdo_sqlite')) {
2932
throw new Nette\NotSupportedException('SQLiteJournal requires PHP extension pdo_sqlite which is not loaded.');
3033
}
34+
$this->path = $path;
35+
}
36+
3137

32-
$this->pdo = new \PDO('sqlite:' . $path);
38+
private function open()
39+
{
40+
$this->pdo = new \PDO('sqlite:' . $this->path);
3341
$this->pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
3442
$this->pdo->exec('
3543
PRAGMA foreign_keys = OFF;
@@ -58,6 +66,9 @@ public function __construct($path)
5866
*/
5967
public function write($key, array $dependencies)
6068
{
69+
if (!$this->pdo) {
70+
$this->open();
71+
}
6172
$this->pdo->exec('BEGIN');
6273

6374
if (!empty($dependencies[Cache::TAGS])) {
@@ -89,6 +100,9 @@ public function write($key, array $dependencies)
89100
*/
90101
public function clean(array $conditions)
91102
{
103+
if (!$this->pdo) {
104+
$this->open();
105+
}
92106
if (!empty($conditions[Cache::ALL])) {
93107
$this->pdo->exec('
94108
BEGIN;

0 commit comments

Comments
 (0)