# Internal cache ((pro))

imgproxy Pro provides an internal cache that stores processed images on disk or in cloud storage. This cache can act as both a primary and a secondary cache, serving as a fallback when your CDN cache misses.

:::tip
While putting a CDN in front of imgproxy is and will always be a best practice, the internal cache provides long-term storage for cases that require an additional caching layer.
:::

## Why use internal cache?

The internal cache provides long-term persistent storage for processed images, unlike CDNs, which typically delete rarely accessed content. It stores images in a single location rather than across multiple edge stores, eliminating cache misses when requests hit different edges. The cache is designed specifically for imgproxy, working seamlessly with features like modern image format detection and client hints support that generic external caches don't understand by default.

The cache is protected by the same security measures as imgproxy itself, including URL signatures and processing restrictions. Importantly, URL signatures are not part of the cache key, so you can rotate keys or use multiple key/salt pairs without invalidating cached images. You maintain full control over where the cache is stored and how it integrates with your infrastructure.

## Configuration

You need to define the following config variables to enable the internal cache:

* [`IMGPROXY_CACHE_USE`]: the cache storage adapter to use. Can be `fs`, `s3`, `gcs`, `abs` (Azure Blob Storage), or `swift` (OpenStack Swift). When blank, the cache is disabled. Default: blank
* [`IMGPROXY_CACHE_PATH_PREFIX`]: _(optional)_ a path prefix for the cache files. This can be useful to organize cache files in a specific directory structure. Default: blank
* [`IMGPROXY_CACHE_BUCKET`]: _(optional)_ the bucket name for cloud storage adapters (S3, GCS, ABS, Swift). When using the filesystem adapter, this can be used as an additional path component. Default: blank
* [`IMGPROXY_CACHE_KEY_HEADERS`]: _(optional)_ a list of HTTP request headers (comma-separated) to include in the cache key. This allows caching different versions of the same image based on request headers. Default: blank
* [`IMGPROXY_CACHE_KEY_COOKIES`]: _(optional)_ a list of HTTP request cookies (comma-separated) to include in the cache key. This allows caching different versions of the same image based on cookies. Default: blank
* [`IMGPROXY_CACHE_REPORT_ERRORS`]: When `true`, imgproxy will report cache errors instead of silently falling back to processing without cache. Default: `false`

### Storage configuration

The internal cache supports all the storage backends that imgproxy can read source images from: local filesystem, Amazon S3 and compatible services (Cloudflare R2, DigitalOcean Spaces, MinIO, etc.), Google Cloud Storage, Microsoft Azure Blob Storage, and OpenStack Swift.

Configure the storage backend using `IMGPROXY_CACHE_*` variables:

* For filesystem cache, see [Cache storage: Local filesystem](./internal/local_filesystem.mdx).
* For S3 cache, see [Cache storage: Amazon S3](./internal/amazon_s3.mdx).
* For GCS cache, see [Cache storage: Google Cloud Storage](./internal/google_cloud_storage.mdx).
* For Azure Blob Storage cache, see [Cache storage: Azure Blob Storage](./internal/azure_blob_storage.mdx).
* For Swift cache, see [Cache storage: OpenStack Object Storage ("Swift")](./internal/openstack_swift.mdx).

## Cache key

The cache key is generated based on:

* Source image URL
* Processing options
* Output format
* Optional: Request headers specified in `IMGPROXY_CACHE_KEY_HEADERS`
* Optional: Request cookies specified in `IMGPROXY_CACHE_KEY_COOKIES`

URL signature is **not** part of the cache key, allowing key rotation without invalidating the cache.

## Limitations

* **No manual cache invalidation**: Currently, imgproxy doesn't provide a built-in means to invalidate the cache. However, imgproxy includes the [cachebuster](../usage/processing.mdx#cache-buster) in the cache key, so you can use it to force cache invalidation when needed. Most storage offerings also support object expiration, so you can set a reasonable expiration time for cached images.
* **No cache for info requests**: The internal cache is currently used only for image processing requests. Requests to the `/info` endpoint are not cached.

## How it works

When a request comes in:

1. imgproxy checks the URL signature (if enabled).
2. imgproxy generates the cache key from the request parameters.
3. imgproxy checks if a cached image exists in the configured storage.
4. If the cached image exists and is valid, imgproxy serves it directly.
5. If not, imgproxy processes the image and stores the result in the cache before serving it.

---

## Navigation

- [Getting started](/4-pre/getting_started)
- [imgproxy Pro](https://imgproxy.net#pro)
- [Installation](/4-pre/installation)
- [Configuration](/4-pre/category/configuration)
  - [Configuration options](/4-pre/configuration/options)
  - [Loading environment variables](/4-pre/configuration/loading_environment_variables)
- [Usage](/4-pre/category/usage)
  - [Processing an image](/4-pre/usage/processing)
  - [Getting an image info](/4-pre/usage/getting_info)
  - [Signing a URL](/4-pre/usage/signing_url)
  - [Encrypting a source URL](/4-pre/usage/encrypting_source_url)
  - [Presets](/4-pre/usage/presets)
- [Features](/4-pre/category/features)
  - [Watermark](/4-pre/features/watermark)
  - [Object detection](/4-pre/features/object_detection)
  - [Classification](/4-pre/features/classification)
  - [Autoquality](/4-pre/features/autoquality)
  - [Best format](/4-pre/features/best_format)
  - [Chained pipelines](/4-pre/features/chained_pipelines)
- [Image sources](/4-pre/category/image-sources)
  - [Serving local files](/4-pre/image_sources/local_files)
  - [Serving files from Amazon S3](/4-pre/image_sources/amazon_s3)
  - [Serving files from Google Cloud Storage](/4-pre/image_sources/google_cloud_storage)
  - [Serving files from Azure Blob Storage](/4-pre/image_sources/azure_blob_storage)
  - [Serving files from OpenStack Object Storage ("Swift")](/4-pre/image_sources/openstack_swift)
- [Cache](/4-pre/category/cache)
  - [External cache](/4-pre/cache/external)
  - [Internal cache](/4-pre/cache/internal)
    - [Internal cache: Local filesystem](/4-pre/cache/internal/local_filesystem)
    - [Internal cache: Amazon S3](/4-pre/cache/internal/amazon_s3)
    - [Internal cache: Google Cloud Storage](/4-pre/cache/internal/google_cloud_storage)
    - [Internal cache: Azure Blob Storage](/4-pre/cache/internal/azure_blob_storage)
    - [Internal cache: OpenStack Object Storage ("Swift")](/4-pre/cache/internal/openstack_swift)
- [Monitoring](/4-pre/category/monitoring)
  - [New Relic](/4-pre/monitoring/new_relic)
  - [Prometheus](/4-pre/monitoring/prometheus)
  - [Datadog](/4-pre/monitoring/datadog)
  - [OpenTelemetry](/4-pre/monitoring/open_telemetry)
  - [Amazon CloudWatch](/4-pre/monitoring/cloud_watch)
- [Image formats support](/4-pre/image_formats_support)
- [About the processing pipeline](/4-pre/about_processing_pipeline)
- [Health check](/4-pre/healthcheck)
- [Memory usage tweaks](/4-pre/memory_usage_tweaks)
