Skip to content

Commit 4a133f1

Browse files
committed
✨ Add TDBMService::clearBeanCache method
This method can be used to cleanup every bean so long-running process won't keep old data.
1 parent 5eee478 commit 4a133f1

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

src/NativeWeakrefObjectStorage.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,14 @@ public function remove(string $tableName, $id): void
9494
unset($this->objects[$tableName][$id]);
9595
}
9696

97+
/**
98+
* Removes all objects from the storage.
99+
*/
100+
public function clear(): void
101+
{
102+
$this->objects = array();
103+
}
104+
97105
private function cleanupDanglingWeakRefs(): void
98106
{
99107
foreach ($this->objects as $tableName => $table) {

src/ObjectStorageInterface.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,9 @@ public function get(string $tableName, $id): ?DbRow;
4141
* @param string|int $id
4242
*/
4343
public function remove(string $tableName, $id): void;
44+
45+
/**
46+
* Removes all objects from the storage.
47+
*/
48+
public function clear(): void;
4449
}

src/TDBMService.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1554,4 +1554,14 @@ public function setLogLevel(string $level): void
15541554
{
15551555
$this->logger = new LevelFilter($this->rootLogger, $level);
15561556
}
1557+
1558+
/**
1559+
* Clear TDBM's bean cache
1560+
*
1561+
* This can be used in long-running processes to cleanup everything.
1562+
*/
1563+
public function clearBeanCache(): void
1564+
{
1565+
$this->objectStorage->clear();
1566+
}
15571567
}

0 commit comments

Comments
 (0)