Is it OK to have duplicate keys in Surrogate-Key?


#1

I have few questions about surrogate keys.

  1. What is the limit of keys in Surrogate-Key header?
  2. Is there any performance issues with having multiple surrogate keys?
  3. Is there a problem with having duplicate key in Surrogate-Key? The reason is, if I have VCL code that would add surrogate key, it would run both on edge and on shield. So I want to know if I have to check it, before adding, or it’s ok to add without checking.
  4. Is it OK to have space at the beginning of Surrogate-Key?
    So if I have following VCL:
    If (beresp.http.Some-Header){
    set beresp.http.Surrogate-Key = beresp.http.Surrogate-Key " my-key";
    }

Is it enough, or I have to check if Surrogate-Key exists and it it already includes “my-key”?


#2
  • What is the limit of keys in Surrogate-Key header?

Please review our docs on Limitations.

  • Is there any performance issues with having multiple surrogate keys?

No, you can add space-delimited strings to the Surrogate-Key header, like this:

Surrogate-Key: key1 key2 key3

I highly recommend to review our docs on Understanding surrogate keys.

  • Is there a problem with having duplicate key in Surrogate-Key? The reason is, if I have VCL code that would add surrogate key, it would run both on edge and on shield. So I want to know if I have to check it, before adding, or it’s ok to add without checking.

I have tested it and it works if you have duplicate keys in your Surrogate-Key header like:

Surrogate-Key: key1 key1 key 2

In my opinion it looks bad and it is definitely not best practice!

  • Is it OK to have space at the beginning of Surrogate-Key? So if I have following VCL:
if (beresp.http.Some-Header) {
   set beresp.http.Surrogate-Key = beresp.http.Surrogate-Key " my-key";
}

Is it enough, or I have to check if Surrogate-Key exists and it it already includes “my-key”?

Let’s say the value for beresp.http.Surrogate-Key equals to foo. You have to add the whitespace in order to have two surrogate keys like:

Surrogate-Key: foo my-key

Without the whitespace you just would define one surrogate key like:

Surrogate-Key: foomy-key

Fastly strips out the Surrogate-Header and creates a mapping from each key to the cached content. In order to see the Surrogate-Key header you can add Fastly-Debug:1 to your cURL command like:

curl -svo /dev/null -H Fastly-Debug:1 http://www.example.com

This is a nice feature when you want to test your Surrogat-Key configuration. Please take a look at Deciphering Fastly-Debug header if you want to learn more about it.