You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A lightweight proxy that captures Ghost CMS cache invalidation signals (`X-Cache-Invalidate` headers) and forwards them to configurable webhook endpoints.
4
4
5
-
This proxy sits between a Ghost CMS instance and clients. It monitors responses from Ghost for the `X-Cache-Invalidate` header and triggers configured webhooks when cache invalidation is needed.
5
+
## Why Use This?
6
6
7
-
When Ghost updates content, it includes an `X-Cache-Invalidate` header in its responses to indicate which content needs cache invalidation. This proxy captures that header and forwards the information to a configurable webhook endpoint, allowing integration with any cache service or CDN.
7
+
Ghost provides webhook functionality, but it has limitations:
8
8
9
-
This functionality is based on the cache invalidation mechanism implemented in Ghost as described in [TryGhost/Ghost issue #570](https://github.com/TryGhost/Ghost/issues/570), which established the standard for how Ghost communicates which content needs to be purged from caches.
9
+
- Webhooks don't capture all types of content updates (without setting up multiple webhook types)
10
+
- The `site.changed` webhook only tells you *that* something changed, not *what* exactly
11
+
- Webhooks are stored in the database, creating persistent configuration that follows site migrations
12
+
- Managing webhooks across multiple sites becomes a maintenance burden
13
+
14
+
This proxy solves these issues by monitoring the `X-Cache-Invalidate` header that Ghost sends with all content updates, including theme changes, route modifications, and other site-wide changes.
10
15
11
-
## Project History
12
16
13
-
This project evolved from [ghost-bunnycdn-perma-cache-purger](https://github.com/magicpages/ghost-bunnycdn-perma-cache-purger), which was specifically designed to work with BunnyCDN. While the original project served its purpose well, this version has been abstracted to work with any webhook-capable CDN or cache system, making it more versatile for different hosting setups. The core functionality of monitoring Ghost's X-Cache-Invalidate headers remains the same, but the cache purging mechanism has been generalized to support configurable webhooks.
14
17
15
18
## Usage
19
+
The `magicpages/ghost-cache-invalidation-proxy` Docker image is available on
20
+
[Docker Hub](https://hub.docker.com/r/magicpages/ghost-cache-invalidation-proxy). It can be used to deploy the proxy as part of a Docker Compose stack alongside Ghost.
16
21
17
-
The `magicpages/ghost-cache-invalidation-proxy` Docker image is available on [Docker Hub](https://hub.docker.com/r/magicpages/ghost-cache-invalidation-proxy). It can be used to deploy the proxy as part of a Docker Compose stack alongside Ghost.
22
+
## How It Works
18
23
19
-
### Environment Variables
24
+
The proxy sits between your Ghost instance and the internet, monitoring traffic for the `X-Cache-Invalidate` header. When it detects this header, it extracts the invalidation patterns and forwards them to your configured webhook endpoints.
20
25
21
-
#### Required variables
26
+
This approach is particularly valuable for:
27
+
- Managed hosting providers
28
+
- Organizations running multiple Ghost sites
29
+
- Anyone wanting precise cache invalidation without webhook management overhead
22
30
23
-
-`GHOST_URL`: The URL of your Ghost CMS instance. Ideally, the hostname of your Ghost container and the port it listens on (e.g., `http://ghost:2368`).
24
-
-`WEBHOOK_URL`: The URL of the webhook endpoint to call when cache invalidation is needed.
31
+
## Installation
25
32
26
-
#### Optional variables
33
+
###Using Docker (recommended)
27
34
28
-
-`PORT`: The port on which the proxy listens for incoming requests. Defaults to `3000`.
29
-
-`DEBUG`: Set to `true` to enable debug logging. Defaults to `false`.
30
-
-`WEBHOOK_METHOD`: HTTP method to use for the webhook call. Defaults to `POST`.
31
-
-`WEBHOOK_SECRET`: Secret key for webhook authentication. Will be used in the Authorization header if provided.
32
-
-`WEBHOOK_HEADERS`: JSON string of additional headers to include in the webhook request.
33
-
-`WEBHOOK_BODY_TEMPLATE`: JSON template for the webhook request body. Supports the following variables:
34
-
-`${urls}`: Array of URLs/patterns from the `X-Cache-Invalidate` header.
35
-
-`${purgeAll}`: Boolean indicating if all cache should be purged.
36
-
-`${timestamp}`: Current timestamp.
37
-
-`${pattern}`: Raw pattern from the `X-Cache-Invalidate` header.
38
-
-`WEBHOOK_RETRY_COUNT`: Number of retry attempts for failed webhook calls. Defaults to `3`.
39
-
-`WEBHOOK_RETRY_DELAY`: Delay in milliseconds between retry attempts. Defaults to `1000`.
**Note**: Cloudflare has limits on how many URLs you can purge in a single API call:
103
-
- Free/Pro/Business plans: Maximum of 30 URLs per request
104
-
- Enterprise plans: Maximum of 500 URLs per request
105
-
106
-
If your Ghost updates might generate more URLs than these limits, consider implementing additional logic to batch requests (e.g. building your own webhook endpoint that batches requests).
107
-
108
-
## How It Works
109
121
110
-
1. The proxy forwards all client requests to the Ghost CMS instance.
111
-
2. When Ghost responds, the proxy checks for the `X-Cache-Invalidate` header.
112
-
3. If the header is present, the proxy extracts the invalidation patterns and constructs a webhook payload.
113
-
4. The webhook is called with the configured parameters, headers, and body.
114
-
5. The proxy supports retries for failed webhook calls.
115
122
116
123
## License
117
124
118
125
This project is licensed under the MIT License.
119
126
120
127
## Contributing
121
128
122
-
If you have any ideas for improvements or new features, feel free to open an issue or submit a pull request.
129
+
If you have any ideas for improvements or new features, feel free to open an
0 commit comments