Skip to content

Commit 23483a2

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 7b53545 commit 23483a2

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
@@ -1559,4 +1559,14 @@ public function setLogLevel(string $level): void
15591559
{
15601560
$this->logger = new LevelFilter($this->rootLogger, $level);
15611561
}
1562+
1563+
/**
1564+
* Clear TDBM's bean cache
1565+
*
1566+
* This can be used in long-running processes to cleanup everything.
1567+
*/
1568+
public function clearBeanCache(): void
1569+
{
1570+
$this->objectStorage->clear();
1571+
}
15621572
}

0 commit comments

Comments
 (0)