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

# Caching

> A smart caching layer to improve performance

OGify includes a built-in caching system to improve performance by reducing redundant network requests for fonts and emojis. You can configure caching when creating a renderer.

## Configuration

<Tabs>
  <Tab title="Memory Cache">
    Fast in-memory cache with LRU eviction (default)

    ```typescript theme={null}
    import { createRenderer } from '@ogify/core';

    const renderer = createRenderer({
      templates: { /* ... */ },
      cache: {
        type: 'memory',
        ttl: 3600000, // 1 hour (optional)
        max: 100      // Max items (optional)
      }
    });
    ```
  </Tab>

  <Tab title="Filesystem Cache">
    Persistent cache stored on disk

    ```typescript theme={null}
    import { createRenderer } from '@ogify/core';

    const renderer = createRenderer({
      templates: { /* ... */ },
      cache: {
        type: 'filesystem',
        dir: '.cache/ogify',  // Cache directory
        ttl: 3600000,         // 1 hour (optional)
        max: 100              // Max items (optional)
      }
    });
    ```
  </Tab>
</Tabs>

## What is Cached?

<AccordionGroup>
  <Accordion icon="font" title="Remote Fonts">
    Fonts downloaded from Google Fonts or other URLs are cached to avoid
    repeated network requests.
  </Accordion>

  {" "}

  <Accordion icon="face-smile" title="Emoji Assets">
    Emoji images from providers like Twemoji, Fluent, etc. are cached for faster
    rendering.
  </Accordion>

  <Accordion icon="image" title="Generated Images">
    Rendered PNG buffers are cached by a key derived from the template ID,
    merged parameters, and render options. Identical requests return the cached
    buffer without re-rendering.
  </Accordion>
</AccordionGroup>

## Concurrent Render Deduplication

When multiple requests arrive with the same cache key before the first render completes, OGify deduplicates them automatically. All callers share the same in-flight `Promise` and receive the same PNG buffer once rendering finishes.

This prevents redundant Satori/Resvg work during traffic spikes or parallel page builds.

## Disabling Cache

<Warning>Not recommended for production environments</Warning>

To disable caching completely:

```typescript theme={null}
const renderer = createRenderer({
  // ...
  cache: false,
});
```
