Skip to content

Commit

Permalink
✨ Add TDBMService::clearBeanCache method
Browse files Browse the repository at this point in the history
This method can be used to cleanup every bean so long-running process won't keep old data.
  • Loading branch information
homersimpsons committed Jan 17, 2024
1 parent 7b53545 commit b8f013a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/NativeWeakrefObjectStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
5 changes: 5 additions & 0 deletions src/ObjectStorageInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
10 changes: 10 additions & 0 deletions src/TDBMService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

0 comments on commit b8f013a

Please sign in to comment.