Skip to content

Commit 22cee7a

Browse files
committed
storage: Emit cache-tags metadata on tagged uploads
This wires `cache_tags()` into `attributes()`, so every taggable upload carries an `x-amz-meta-cache-tags` entry. The S3 backend surfaces that header for the CDNs to read at cache-fill time, while the local-filesystem dev backend keeps no-oping attributes. Untagged global objects stay metadata-free.
1 parent 40bb667 commit 22cee7a

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

src/storage.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,9 @@ impl<'a> StorageKey<'a> {
471471
if let Some(cache_control) = self.cache_control() {
472472
attributes.insert(Attribute::CacheControl, cache_control.into());
473473
}
474+
if let Some(cache_tags) = self.cache_tags() {
475+
attributes.insert(Attribute::Metadata("cache-tags".into()), cache_tags.into());
476+
}
474477
attributes
475478
}
476479
}
@@ -660,6 +663,39 @@ mod tests {
660663
}
661664
}
662665

666+
async fn cache_tags_metadata(storage: &Storage, key: &StorageKey<'_>) -> Option<String> {
667+
let result = storage.store.get(&key.path()).await.unwrap();
668+
result
669+
.attributes
670+
.get(&Attribute::Metadata("cache-tags".into()))
671+
.map(|value| value.as_ref().to_string())
672+
}
673+
674+
#[tokio::test]
675+
async fn upload_sets_cache_tags_metadata() {
676+
use claims::{assert_none, assert_some_eq};
677+
678+
let s = Storage::from_config(&StorageConfig::in_memory());
679+
680+
let key = StorageKey::for_crate_file("foo", "1.2.3");
681+
s.upload(&key, Bytes::new().into()).await.unwrap();
682+
assert_some_eq!(
683+
cache_tags_metadata(&s, &key).await,
684+
"crate:foo,release:foo@1.2.3"
685+
);
686+
687+
let key = StorageKey::for_crate_zip("foo", "1.2.3");
688+
s.upload_stream(&key, &b"fake zip data"[..]).await.unwrap();
689+
assert_some_eq!(
690+
cache_tags_metadata(&s, &key).await,
691+
"crate:foo,release:foo@1.2.3"
692+
);
693+
694+
let key = StorageKey::DbDumpTar;
695+
s.upload_stream(&key, &b"fake db dump"[..]).await.unwrap();
696+
assert_none!(cache_tags_metadata(&s, &key).await);
697+
}
698+
663699
#[tokio::test]
664700
async fn delete_all_crate_files() {
665701
let storage = prepare().await;

0 commit comments

Comments
 (0)