laravel / ideas

Issues board used for Laravel internals discussions.
938 stars 28 forks source link

[REQUEST] Enable flush method from dynamoDB cache #2652

Closed didix16 closed 3 years ago

didix16 commented 3 years ago

Discussed in https://github.com/laravel/framework/discussions/37855

Originally posted by **didix16** June 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: ```php /** * 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: ```php // @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, ...whatever 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.
crynobone commented 3 years ago

Wouldn't just increase your DynamoDB cost? https://aws.amazon.com/dynamodb/pricing/

didix16 commented 3 years ago

Then maybe the best approach would be deleting the entire table and recreating it, making in total amount of 2 requests, one for deleting the table and another one for creating it again

driesvints commented 3 years ago

Heya, thanks for submitting this.

This seems like a feature request or an improvement so I'm moving this to the ideas repository instead. It's best to post these in the ideas repository in the future to get support for your idea. After that you may send a PR to the framework. Please only use the laravel/framework issue tracker to report bugs and issues with the framework.

Thanks!