I'm using Laravel Vapor for a serverless project and also I'm using DynamoDB as a caching system. I just realized that flush method is throwing and Exception:
/**
* Remove all items from the cache.
*
* @return bool
*
* @throws \RuntimeException
*/
public function flush()
{
throw new RuntimeException('DynamoDb does not support flushing an entire table. Please create a new table.');
}
I don't understand why because it can be implemented by using the DynamoDbClient::scan method and then delete all items looping through them or just deleting the table and recreating it again.
Here is my approach:
// @method \Aws\Result scan(array $args = []) <== This is from DynamoDBClient class
/**
* Remove all items from the cache.
*
* @return bool
*/
public function flush()
{
// This returns the entire items list on dynamoDB table
$items = $this->dynamo->scan([
'TableName' => $this->table,
...what ever the options this API call needs ....
]);
$result = true;
// I dont know how the scan method result and item structure are but suppose it has a getKey() method to get the key....
foreach($items as $item){
$result = $this->forget($item->getKey()) && $result;
}
// if all items could be deleted then flush will return true, else false.
return $result;
}
Hi everyone,
I'm using Laravel Vapor for a serverless project and also I'm using DynamoDB as a caching system. I just realized that flush method is throwing and Exception:
I don't understand why because it can be implemented by using the DynamoDbClient::scan method and then delete all items looping through them or just deleting the table and recreating it again.
Here is my approach:
So what do you think? Hope could be implemented.
Thanks in advance.