Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Add TDBMService::clearBeanCache method #283

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
}
}
Loading