> ## Documentation Index
> Fetch the complete documentation index at: https://gcore.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Modify cache key

A cache key is a unique identifier for each object stored in the cache. It's generated based on specific request attributes like URL, query parameters, headers, or cookies.

Web servers and proxies like Nginx combine these attributes in cache keys to ensure that the correct version of the content is served to users. Properly configured cache keys also improve your website's performance as they prevent unnecessary server load and speed up content delivery.

<Tip>
  **Tip**

  If you want to modify your cache key via API, refer to our [API documentation](/api-reference/cdn/cdn-resources/change-cdn-resource-1).
</Tip>

## Update cache key in CDN resource settings

You can modify the structure of your cache key by adjusting variables that capture essential request information, such as URI or the value of the Host header.

<Info>
  **Info**

  Consider that enabling and updating the **Cache key modification** feature can invalidate your current cache and affect the cache hit ratio. Furthermore, the [Purge by pattern](/cdn/clear-cdn-resource-cache-by-url-pattern-or-all) functionality won't work.
</Info>

To modify the cache key:

1\. In the [Gcore Customer Portal](https://portal.gcore.com/accounts/reports/dashboard), navigate to CDN. You'll be directed to the **CDN resources** page.

2\. Find the resource where you want to modify the cache key and click the CNAME to open its settings.

<Frame>
  <img src="https://mintcdn.com/gcore/eza8d1iXcR57qhAl/images/docs/cdn/cdn-resource-options/cache/modify-cache-key/cdn-resource-name.png?fit=max&auto=format&n=eza8d1iXcR57qhAl&q=85&s=5212bb333abc745d8bb97c13498cf055" alt="CDN resource" width="3368" height="1112" data-path="images/docs/cdn/cdn-resource-options/cache/modify-cache-key/cdn-resource-name.png" />
</Frame>

3\. In the **Cache** section, click **Cache key modification**.

4\. Turn on the **Enable cache key modification** toggle and add the relevant [supported variables](/cdn/cdn-resource-options/cache/modify-cache-key#supported-variables), which are listed in the following section.

<Frame>
  <img src="https://mintcdn.com/gcore/eza8d1iXcR57qhAl/images/docs/cdn/cdn-resource-options/cache/modify-cache-key/cache-key-modification-section.png?fit=max&auto=format&n=eza8d1iXcR57qhAl&q=85&s=5037abcc56602998f8fb6f47d24d0caf" alt="Cache key modification settings" width="5236" height="1340" data-path="images/docs/cdn/cdn-resource-options/cache/modify-cache-key/cache-key-modification-section.png" />
</Frame>

5\. Click **Save changes** to apply the updates.

You've successfully modified the cache key for your resource.

## Supported variables

You can use the following variable to modify your resource's cache key:

* `$request_uri`: The full original request URI. If used with the [rewrite feature](/cdn/cdn-resource-options/rewrite-redirect-requests-from-the-cdn-to-the-origin) in conjunction with this option, this variable retains the value of the original URI, not the rewritten one.
* `$scheme`: The protocol used in the request.
* `$uri`: The current normalized URI in the request. The value of this variable may change during request processing. For example, it'll change during internal redirects or when using index files.

## Best practices and considerations

When configuring a cache key, take into account the following aspects to ensure optimal cache behavior:

* Using both `$uri` and `$request_uri` cache keys simultaneously will result in the cache following the `$request_uri` key—query strings won't be ignored because `$request_uri` includes the query string.

* The `$scheme` cache key does not work correctly when the Redirect HTTP to HTTPS option is enabled. All requests will be redirected to HTTPS, with no cache under the `$scheme` key.

* Using the `$uri` cache key overrides the [Ignore query string](/cdn/cdn-resource-options/cache/ignore-the-set-cookie-or-query-string-parameters-when-caching-content-on-cdn-servers) option.

* Cache keys restricted or added by administrators can't be modified by the client. You can only select from the available options or [contact support](mailto:support@gcore.com) to request changes to such keys.

* When you use modified cache keys, prefetch may not cover all possible cache cases. For instance, if your cache key includes both the `$request_method` and `$uri`, prefetching will result in warm-only HEAD requests. GET requests won't be preloaded into the cache.
