feat(storage): add CDN cache purging for files and buckets - #1358
AndroidPoet wants to merge 1 commit into
Conversation
Adds `StorageFileApi.purgeCache(path:transformationsOnly:)` and `SupabaseStorageClient.purgeBucketCache(_:transformationsOnly:)`, covering `storage.file_buckets.purge_cache` and `storage.file_buckets.purge_bucket_cache`.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (6)
Included review availability: Your plan provides up to 4 included reviews per hour; 3 remain after this review. 📝 SummarySummary by CodeRabbit
WalkthroughStorage adds file-level and bucket-level cache purge APIs. Both APIs send DELETE requests to CDN cache endpoints. When Sequence Diagram(s)sequenceDiagram
participant Caller
participant StorageSDK
participant CDNCacheEndpoint
Caller->>StorageSDK: Request file or bucket cache purge
StorageSDK->>CDNCacheEndpoint: DELETE cache endpoint
CDNCacheEndpoint-->>StorageSDK: Success response
StorageSDK-->>Caller: Completion
Priority: ➖ Normal Change: Feature Merge Risk: ⚪ Minimal · up to The new cache-purge APIs are covered for file, bucket, transformation-only, and encoded-path requests. No actionable merge risk remains. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Adds
purgeCache(path:transformationsOnly:)on a bucket's file API andpurgeBucketCache(_:transformationsOnly:)on the Storage client, over Storage'sDELETE /cdn/{bucket}/{path}andDELETE /cdn/{bucket}endpoints. After replacing a file at the same path, a backend can drop the stale CDN copy instead of waiting outcacheControlor adding a cache-busting parameter to every URL.Marks
storage.file_buckets.purge_cacheandstorage.file_buckets.purge_bucket_cacheimplemented insdk-compliance.yaml. The JS and Flutter clients already ship both.Shape
emptyBucketanddeleteBucket. Storage answers{"message":"success"}, which carries nothing a caller can act on.transformationsOnly:becomes?transformations=true, sent only whentrue. JS and Flutter name ittransformations, buttransformations: truereads as "purge the variants too", when it actually purges only the variants and leaves the original cached._getFinalPathandappendingPathComponentasinfoandexists, so a leading/is stripped and the key is percent-encoded. The JS client first shipped this without encoding and fixed it afterwards (fix(storage): url-encode object key in CDN purge methods supabase-js#2545);purgeCachePercentEncodesThePathpins it here.Worth knowing
CDN_PURGE_ENDPOINT_URL, plus thepurgeCachetenant feature on multi-tenant deployments). The doc comments say so.transformationsflag arrived in Storage v1.61.0 (feat: add ability to purge cdn for whole buckets, tenant, and transformations storage#1133). On an older self-hosted Storage,purgeBucketCachegets a route-not-found 404, andpurgeCache(path:transformationsOnly: true)purges the whole file, because the older file route ignores the query.Testing
Five request-snapshot tests: a file, a file with
transformationsOnly, a file path that needs percent-encoding, a bucket, and a bucket withtransformationsOnly. Dropping the query item makes bothtransformationsOnlytests fail.I also ran all four calls through the SDK with a throwaway test (not part of this PR) against Storage v1.77.4 on the local stack, with
CDN_PURGE_ENDPOINT_URLpointed at a stub that logs what Storage forwards:The two file calls passed
folder/my file.pngand/folder/my file.png, and both reached the purge endpoint as the same object name. The bucket call with the anon key threwStorageErrorwith kind.server, status 403 andAccess denied: Invalid role.The capability matrix checks from
validate-sdk-compliance-swift.yml(pinnedcapability-matrix-v1.6.0) pass locally againstmain, with symbol graphs dumped and normalized the way CI does it.Review first
The
transformationsOnly:label, which departs from the JS and Flutter spelling on purpose.