Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions packages/storage_client/lib/src/storage_bucket_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,35 @@ class StorageBucketApi {
return (response as Map<String, dynamic>)['message'] as String;
}

/// Purges the CDN cache for an entire bucket.
///
/// Invalidates the CDN cache for every object in the bucket [id]. Maps to
/// `DELETE /cdn/{bucket}` on the storage server.
///
/// When [transformations] is `true`, only the resized/formatted variants are
/// purged, leaving the original cached files intact. When omitted the bucket
/// cache is purged.
///
/// Requires the service-role key and the tenant `purgeCache` feature to be
/// enabled on the storage server.
Future<String> purgeBucketCache(
String id, {
bool transformations = false,
}) async {
var requestUrl = Uri.parse('$url/cdn/$id');
if (transformations) {
requestUrl = requestUrl.replace(
queryParameters: {'transformations': 'true'},
);
}
final response = await storageFetch.delete(
requestUrl.toString(),
{},
options: FetchOptions(headers),
);
return (response as Map<String, dynamic>)['message'] as String;
}

/// Creates a new analytics bucket backed by the Apache Iceberg table format.
///
/// [id] is the unique identifier for the bucket you are creating.
Expand Down
29 changes: 29 additions & 0 deletions packages/storage_client/test/basic_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,35 @@ void main() {
expect(response, 'Deleted');
});

test('should purgeBucketCache issuing DELETE to /cdn/{bucket}', () async {
customHttpClient.response = {'message': 'success'};

final response = await client.purgeBucketCache('test_bucket');

final request = customHttpClient.receivedRequests.last;
expect(request.method, 'DELETE');
expect(
request.url.toString(),
endsWith('/storage/v1/cdn/test_bucket'),
);
expect(request.url.query, isEmpty);
expect(response, 'success');
});

test('should purgeBucketCache with transformations query param', () async {
customHttpClient.response = {'message': 'success'};

final response = await client.purgeBucketCache(
'test_bucket',
transformations: true,
);

final request = customHttpClient.receivedRequests.last;
expect(request.method, 'DELETE');
expect(request.url.queryParameters['transformations'], 'true');
expect(response, 'success');
});

test('should create analytics bucket', () async {
customHttpClient.response = testAnalyticsBucketJson;

Expand Down
4 changes: 4 additions & 0 deletions sdk-compliance.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,10 @@ features:
status: implemented
symbols:
- StorageFileApi.purgeCache
storage.file_buckets.purge_bucket_cache:
status: implemented
symbols:
- StorageBucketApi.purgeBucketCache
storage.file_buckets.create_signed_url:
status: implemented
symbols:
Expand Down
Loading