aboutsummaryrefslogtreecommitdiffhomepage
path: root/Digitigrade/Model.php
diff options
context:
space:
mode:
Diffstat (limited to 'Digitigrade/Model.php')
-rw-r--r--Digitigrade/Model.php16
1 files changed, 12 insertions, 4 deletions
diff --git a/Digitigrade/Model.php b/Digitigrade/Model.php
index 6a4fe27..9ce759a 100644
--- a/Digitigrade/Model.php
+++ b/Digitigrade/Model.php
@@ -6,7 +6,7 @@ use Digitigrade\Model\FetchableModel;
abstract class Model {
private bool $saved = false;
- protected static array $cachedLookups = [];
+ private static array $cachedLookups = [];
private static bool $memoEnabled = false;
protected function setOwnerId(int $id) {
@@ -164,7 +164,7 @@ abstract class Model {
$result = static::fromDbRow($stmt->fetch(\PDO::FETCH_ASSOC));
if (self::$memoEnabled) {
- self::$cachedLookups[$memoKey] = $result;
+ self::$cachedLookups[$memoKey] = &$result;
}
return $result;
}
@@ -201,7 +201,7 @@ abstract class Model {
return static::fromDbRow($row);
}, $stmt->fetchAll(\PDO::FETCH_ASSOC));
if (self::$memoEnabled) {
- self::$cachedLookups[$memoKey] = $result;
+ self::$cachedLookups[$memoKey] = &$result;
}
return $result;
}
@@ -229,7 +229,7 @@ abstract class Model {
$result = $stmt->fetchColumn(0);
if (self::$memoEnabled) {
- self::$cachedLookups[$memoKey] = $result;
+ self::$cachedLookups[$memoKey] = &$result;
}
return $result;
}
@@ -326,6 +326,14 @@ abstract class Model {
$tableName = self::mangleName($className);
$db->exec("DELETE FROM $tableName WHERE $where");
+
+ if (self::$memoEnabled) {
+ $key = array_search($this, self::$cachedLookups, strict: true);
+ while ($key !== false) {
+ unset(self::$cachedLookups[$key]);
+ $key = array_search($this, self::$cachedLookups, strict: true);
+ }
+ }
}
/**