diff --git a/src/NativeWeakrefObjectStorage.php b/src/NativeWeakrefObjectStorage.php index b2265d0b..2d6c1d48 100644 --- a/src/NativeWeakrefObjectStorage.php +++ b/src/NativeWeakrefObjectStorage.php @@ -94,6 +94,14 @@ public function remove(string $tableName, $id): void unset($this->objects[$tableName][$id]); } + /** + * Removes all objects from the storage. + */ + public function clear(): void + { + $this->objects = array(); + } + private function cleanupDanglingWeakRefs(): void { foreach ($this->objects as $tableName => $table) { diff --git a/src/ObjectStorageInterface.php b/src/ObjectStorageInterface.php index 53064bec..f762e604 100644 --- a/src/ObjectStorageInterface.php +++ b/src/ObjectStorageInterface.php @@ -41,4 +41,9 @@ public function get(string $tableName, $id): ?DbRow; * @param string|int $id */ public function remove(string $tableName, $id): void; + + /** + * Removes all objects from the storage. + */ + public function clear(): void; } diff --git a/src/TDBMService.php b/src/TDBMService.php index ecfa1be5..a1ff6a14 100644 --- a/src/TDBMService.php +++ b/src/TDBMService.php @@ -1559,4 +1559,14 @@ public function setLogLevel(string $level): void { $this->logger = new LevelFilter($this->rootLogger, $level); } + + /** + * Clear TDBM's bean cache + * + * This can be used in long-running processes to cleanup everything. + */ + public function clearBeanCache(): void + { + $this->objectStorage->clear(); + } }