Skip to content
This repository has been archived by the owner on Jul 16, 2021. It is now read-only.

[Feature] Enable flush method from dynamoDB #2653

Open
didix16 opened this issue Jun 29, 2021 · 0 comments
Open

[Feature] Enable flush method from dynamoDB #2653

didix16 opened this issue Jun 29, 2021 · 0 comments

Comments

@didix16
Copy link

didix16 commented Jun 29, 2021

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:

/**
     * 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;
    }

So what do you think? Hope could be implemented.

Thanks in advance.

@didix16 didix16 changed the title [Proposal] Enable flush method from dynamoDB [Feature] Enable flush method from dynamoDB Jun 29, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant