Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions config/packages/api_platform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,7 @@ api_platform:
json: ['application/json']
swagger:
versions: [3]
http_cache:
invalidation:
enabled: true
varnish_urls: ['http://varnish']
15 changes: 13 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,24 @@ services:
- 'php_cache:/var/www/html/var/cache'
- 'php_public_images:/var/www/html/web/images'

varnish:
image: varnish:7
depends_on:
- nginx
ports:
- '80:80'
volumes:
- ./docker/varnish/default.vcl:/etc/varnish/default.vcl:ro
environment:
- VARNISH_SIZE=256M

nginx:
image: 'nginx:1.25-alpine'
depends_on:
- php
- centrifugo
ports:
- '80:80'
expose:
- 8080
volumes:
- './docker/nginx/conf.d:/etc/nginx/conf.d:ro'
- './web:/var/www/html/web:ro'
Expand Down
2 changes: 2 additions & 0 deletions docker/nginx/conf.d/default.conf
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ map $http_upgrade $connection_upgrade {
}

server {
listen 8080;
server_name _;

root /var/www/html/web;

Expand Down
69 changes: 69 additions & 0 deletions docker/varnish/default.vcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
vcl 4.1;

backend default {
.host = "nginx";
.port = "8080";
}

acl purge {
"127.0.0.1";
"nginx";
"php";
"varnish";
}

sub vcl_recv {
if (req.method == "BAN") {
if (!client.ip ~ purge) {
return (synth(403, "Forbidden"));
}
if (req.http.Cache-Tags) {
ban("obj.http.Cache-Tags ~ " + req.http.Cache-Tags);
return (synth(200, "Banned"));
}
return (synth(400, "Missing Cache-Tags header"));
}

if (req.method == "PURGE") {
if (!client.ip ~ purge) {
return (synth(403, "Forbidden"));
}
return (purge);
}

if (req.method != "GET" && req.method != "HEAD") {
return (pass);
}

# Avoid caching Centrifugo & WebSocket
if (req.url ~ "^/centrifugo") {
return (pass);
}

return (hash);
}

sub vcl_hash {
hash_data(req.http.host);
hash_data(req.url);
}

sub vcl_backend_response {
if (beresp.http.Cache-Control ~ "private") {
set beresp.uncacheable = true;
} else {
set beresp.ttl = 1h;
}

if (beresp.http.Cache-Tags) {
set beresp.http.X-Cache-Tags = beresp.http.Cache-Tags;
}
}

sub vcl_deliver {
if (obj.hits > 0) {
set resp.http.X-Cache = "HIT";
} else {
set resp.http.X-Cache = "MISS";
}
}
4 changes: 4 additions & 0 deletions src/Entity/LocalBusiness.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@
#[Vich\Uploadable]
#[ApiResource(
shortName: 'Restaurant',
cacheHeaders: [
'max_age' => 60,
'public' => true
],
operations: [
new Get(
normalizationContext: [
Expand Down
Loading