Skip to content

feat: expose purgeCache #229

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open

feat: expose purgeCache #229

wants to merge 5 commits into from

Conversation

mansueli
Copy link
Member

What kind of change does this PR introduce?

The goal is to expose the purgeCache operation from the API to the client libraries.

        "/cdn/{bucketName}/{wildcard}": {
            "delete": {
                "summary": "Purge cache for an object",
                "tags": [
                    "object"
                ],
                "parameters": [
                    {
                        "schema": {
                            "type": "string"
                        },
                        "example": "avatars",
                        "in": "path",
                        "name": "bucketName",
                        "required": true
                    },
                    {
                        "schema": {
                            "type": "string"
                        },
                        "example": "folder/cat.png",
                        "in": "path",
                        "name": "*",
                        "required": true
                    },
                    {
                        "schema": {
                            "type": "string"
                        },
                        "example": "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6ImFub24ifQ.625_WdcF3KHqz5amU0x2X5WWHP-OEs_4qj0ssLNHzTs",
                        "in": "header",
                        "name": "authorization",
                        "required": true
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Successful response",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "description": "Successful response",
                                    "type": "object",
                                    "properties": {
                                        "message": {
                                            "type": "string",
                                            "examples": [
                                                "success"
                                            ]
                                        }
                                    }
                                }
                            }
                        }
                    },
                    "4XX": {
                        "description": "Error response",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "description": "Error response",
                                    "$ref": "#/components/schemas/def-1"
                                }
                            }
                        }
                    }
                }
            }
        },

What is the current behavior?

There's no support this in the client libraries.

What is the new behavior?

The goal is to allow this to be exposed in the supabase-js client e.g:

storage.from(BUCKET_ID).purgeCache('test.png')

Additional context

Add any other context or screenshots.

@mansueli mansueli changed the title expose purgeCache feat: expose purgeCache Jun 20, 2025
@mansueli mansueli requested a review from itslenny June 20, 2025 13:25
@mansueli mansueli requested a review from grdsdev June 23, 2025 15:53
Copy link
Contributor

@itslenny itslenny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great overall. I ran tests against production purging individual objects and folders with 100s of objects and both are working well.

The folder detection is wrong (see other comment) so I get "object not found" for each folder currently, but after that's fixed this should work as expected


// Extract file paths and filter out folders
const filePaths = objects
.filter((obj) => obj.name && !obj.name.endsWith('/')) // Only files, not folders
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

name does not in with / for folders, but folders will have obj.id === null so use that to check for folders instead.

}
}

// Process files in batches to avoid overwhelming the API
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since there is no pause between batches this nested loop behaves exactly the same as not doing batching at all. Add a pause after each batch. It should probably be configurable via options.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, just as a general note this could take a very long time to run and we should probably make a note that somewhere. Purging 1 object takes between 300ms and 600ms

When I ran this (as-is with no pause between batches) it took 91 seconds to purge a folder containing 221 objects.

@grdsdev grdsdev requested a review from mandarini August 6, 2025 18:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants