-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
119 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
# Getting Started | ||
|
||
The bundle is designed to automatically generate and send cache purge requests to HTTP cache backends such as Symfony's | ||
HTTP cache or Varnish. It leverages Doctrine events to detect changes in entities and generates URLs that need to be | ||
purged based on configured routes. | ||
|
||
## Why URL-based Invalidation? | ||
|
||
This bundle uses URL-based invalidation instead of tag-based invalidation due to the following reasons: | ||
|
||
1. **Performance Concerns**: Varnish's tag-based invalidation can lead to slow responses when multiple URLs are | ||
invalidated simultaneously. | ||
1. **Header Size Limitations**: Tags are typically passed through HTTP headers, which have size limitations. This means | ||
not all tags may fit within the header limits. | ||
1. **Cost Implications**: Some CDN providers charge extra for tag-based invalidation, making URL-based purging a more | ||
cost-effective solution. | ||
|
||
## Supported Backends | ||
|
||
The bundle includes built-in support for [Symfony HTTP Cache](https://symfony.com/doc/current/http_cache.html) and a | ||
basic [Varnish](https://varnish-cache.org/) implementation. Each backend is realized by implementing | ||
the [`PurgerInterface`](/src/Purger/PurgerInterface.php). | ||
|
||
It also comes with a `VoidPurger`, which can be used during development when cache purging is not required. The | ||
`VoidPurger` simply ignores all purge requests, making it ideal for non-production environments. Additionally, an | ||
`InMemoryPurger` is provided, designed specifically for testing purposes. The `InMemoryPurger` simulates purging actions | ||
without interacting with external cache services, enabling you to verify your purging logic in tests. | ||
|
||
For advanced use cases, you can create custom purgers by implementing the `PurgerInterface`. This allows you to | ||
integrate with any custom or third-party HTTP cache backend that fits your project requirements. | ||
|
||
### Configuring Symfony's HTTP Cache | ||
|
||
Configure Symfony's HTTP Cache following | ||
the [official documentation](https://symfony.com/doc/current/http_cache.html#symfony-reverse-proxy). | ||
|
||
Enable the Symfony purger with the following configuration: | ||
|
||
```yaml | ||
purgatory: | ||
purger: symfony | ||
``` | ||
### Configuring Varnish Cache | ||
To enable Varnish to support PURGE requests, add the following example configuration to your VCL file. You may need to | ||
customize it based on your specific Varnish setup: | ||
```vcl | ||
acl purge { | ||
"localhost"; | ||
"172.16.0.0"/12; # Common Docker IP range, adjust as needed | ||
# Add more whitelisted IPs here | ||
} | ||
|
||
sub vcl_recv { | ||
if (req.method == "PURGE") { | ||
if (client.ip !~ purge) { | ||
return (synth(405, "Not allowed.")); | ||
} | ||
return (purge); | ||
} | ||
} | ||
``` | ||
|
||
Enable the Varnish purger with the following configuration: | ||
|
||
```yaml | ||
purgatory: | ||
purger: varnish | ||
``` | ||
Optionally, you can specify a list of Varnish hosts: | ||
```yaml | ||
purgatory: | ||
purger: | ||
name: varnish | ||
hosts: | ||
- varnish1.example.com | ||
- varnish2.example.com | ||
- varnish3.example.com | ||
``` | ||
If no hosts are specified, the bundle will use the host from the URL. |