The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
add guide for storage caching
Inianf11070b487d1
diff --git a/apps/reference/docs/guides/storage-caching.mdx b/apps/reference/docs/guides/storage-caching.mdxnew file mode 100644index 00000000000..a0032e6ff26--- /dev/null+++ b/apps/reference/docs/guides/storage-caching.mdx@@ -0,0 +1,32 @@+---+id: storage-caching+title: Storage Caching+description: How Supabase Storage caches objects+sidebar_label: Caching+---++## CDN basics++All assets uploaded to storage are cached on a Content Delivery Network (CDN).++To improve the latency for users all around the world, Supabase uses a CDN. CDNs are a geographically distributed set of servers or **nodes** which caches content from an **origin server**. For Supabase Storage, the origin is the storage server running in the [same region as your project](https://app.supabase.com/project/_/settings/general).++Let’s walk through an example of how a CDN helps with performance. A new bucket is created for a Supabase project launched in Singapore. All requests to the Supabase Storage API first hit the CDN. A user from the United States requests an object and is routed to the U.S. CDN. At this point, that CDN node does not have the object in its cache and pings the origin server in Singapore. Another user, also in the United States, requests the same object and is served directly from the CDN cache in the United States instead of routing the request back to Singapore.++Aside from performance, CDNs also help with security and availability by mitigating Distributed Denial of Service and other application attacks.++## Cache duration++By default, assets are cached both in the CDN and in the user’s browser for 1 hour. After this, the CDN nodes ping the storage server to see if an object has been updated.++You can modify this cache time when you are [uploading](https://supabase.com/docs/reference/javascript/next/storage-from-upload) or [updating](https://supabase.com/docs/reference/javascript/next/storage-from-update) an object by modifying the `cacheControl` parameter.++The cache status of a particular request is sent in the `cf-cache-status` header. A cache status of `MISS` indicates that the CDN node did not have the object in its cache and had to ping the origin to get it. A cache status of `HIT` indicates that the object was sent directly from the CDN.++## Performance++If you expect the object to not change at a given URL, setting a longer cache duration is preferable.++If you need to update the version of the object stored in the CDN, there are various cache-busting techniques you can use. The most common way to do this is to add a version query parameter in the URL. For example, you can use a URL like `/storage/v1/object/sign/profile-pictures/cat.jpg?token=eyJh...&version=1` in your applications and set a long cache time of 1 year. When you want to update the cat picture, you can increment the version query parameter in the URL. The CDN will treat ``/storage/v1/object/sign/profile-pictures/cat.jpg?token=eyJh...&version=2`as a new object and pings the origin for the updated version.++Note that CDNs might still evict your object from their cache if it has not been requested for a while from a specific region. For example, if no user from United States requests your object, it will be removed from the CDN cache even if you set a very long cache control duration.diff --git a/apps/reference/nav/_referenceSidebars.js b/apps/reference/nav/_referenceSidebars.jsindex 18f272594f5..68d5bfed04e 100644--- a/apps/reference/nav/_referenceSidebars.js+++ b/apps/reference/nav/_referenceSidebars.js@@ -182,7 +182,7 @@ const sidebars = {type: 'category',label: 'Storage',collapsed: true,- items: ['guides/storage'],+ items: ['guides/storage', 'guides/storage-caching'],},{type: 'category',