All users can enjoy our Smart Content Management Network for allowing your content to be served as fast as possible.
Thanks to the Smart CDN, your Static Files will automatically be cached in all of our regions whenever they are requested (no manual changes needed). Furthermore, this also gives you the ability to cache the responses of your Lambdas in those regions too. For this to happen, you need to modify your code a little:
For your dynamic responses to be cached in all edge points, adjust your code to send a Cache-Control header containing a
s-maxage (used for shared caches) parameter. Here is an example for caching your response for 365 days:
This is just an example, however.
Although this would be enough for ensuring your responses are cached in all regions available within the Smart CDN, you should generally also include
max-age (used for client caches), so that all clients (e.g., browsers) also know for how long to cache your responses:
Cache-Control: s-maxage=31536000, max-age=0
As you can see above, the header is now instructing the client to expire any caches for the resource immediately. In general, we recommend this because it leverages Now's caches across the Full CDN instead of depending on the client's as well.
An important reason for this recommendation is that you have full control over purging Now's caches (unlike the client's), as you can read below.
If you do not specify a region (which can be done using the
--regions flag in Now CLI), your Lambdas will only be created in the region that is closest to you.
It is recommended that you deploy your Lambdas closest to the data source as possible. If you have a database deployed in Paris, for example, it is natural that you deploy Lambdas to that region as well. If you need to cache, just use cache control headers.
By default, the cache for a response of your deployment is purged once the expiration timeout defined in
s-maxage is reached.
Additionally, we also purge all caches related to a deployment when an alias is created or updated, as this implies that new content needs to be served, thus requiring purging the caches.