Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Purging by regex not working on master #559

Closed
Tracked by #558
mac-chaffee opened this issue Oct 20, 2024 · 2 comments · Fixed by #567
Closed
Tracked by #558

Purging by regex not working on master #559

mac-chaffee opened this issue Oct 20, 2024 · 2 comments · Fixed by #567

Comments

@mac-chaffee
Copy link

Hello, thanks for creating this amazing repo!

I noticed that even after #556 was merged into master, I still can't seem to purge keys by regex. I'm using Caddy and Otter on commit 2968d51.

Here is how to reproduce the issue:
Dockerfile:

FROM --platform=$BUILDPLATFORM caddy:builder-alpine AS builder

ENV CGO_ENABLED=0

ARG TARGETOS
ARG TARGETARCH

ENV GOOS=${TARGETOS} GOARCH=${TARGETARCH}

RUN xcaddy build \
    --with github.com/caddy-dns/cloudflare \
    --with github.com/darkweak/souin/plugins/caddy@2968d51eef04b31925352ac4aaf815ea49f4efbd \
    --with github.com/darkweak/storages/otter/caddy

FROM caddy:alpine

COPY --from=builder /usr/bin/caddy /usr/bin/caddy

Caddyfile:

{
  cache {
    ttl 120s
    otter
    api {
      souin
    }
  }
}

localhost {
  cache
  respond "Hello World!"
}

Test purging by regex:

# Store something in the cache
$ curl -ik https://localhost/                                                   
HTTP/2 200 
alt-svc: h3=":443"; ma=2592000
cache-control: 
cache-status: Souin; fwd=uri-miss; stored; key=GET-https-localhost-/
content-type: text/plain; charset=utf-8
server: Caddy
content-length: 12
date: Sun, 20 Oct 2024 13:50:55 GMT

# Observe it's being cached
$ curl -ik https://localhost/souin-api/souin/surrogate_keys
HTTP/2 200 
alt-svc: h3=":443"; ma=2592000
content-type: application/json
server: Caddy
content-length: 592
date: Sun, 20 Oct 2024 13:51:33 GMT

{"GET-https-localhost-/":"\u0004\"M\u0018dp\ufffd\ufffd\u0000\u0000\u0000\ufffd\ufffdHTTP/0.0 200 OK\r\nAlt-Svc: h3=\":443\"; ma=2592000\r\nCache-Control: \r\nContent-Type: text/plain; charset=utf-8\r\nDate: Sun, 20 Oct 2024 13:50:55 GMT\r\nServer: Caddy\r\nX-Souin-Stored-Length: 12\u001b\u0000\ufffd\nTtl: 2m0s\r\n\r\nHello World!","IDX_GET-https-localhost-/":"\nV\n\u0015GET-https-localhost-/\u0012=\n\f\b\ufffd\ufffdԸ\u0006\u0010\ufffd\ufffdԃ\u0003\u0012\n\b\ufffd\ufffdԸ\u0006\u0010\ufffd\ufffd\u0001\u001a\n\b\ufffd\ufffdԸ\u0006\u0010\ufffd\ufffd\u00012\u0015GET-https-localhost-/"}%  

# Try to purge the cache with a regex
$ curl -ik -X PURGE 'https://localhost/souin-api/souin/.+'
HTTP/2 204 
alt-svc: h3=":443"; ma=2592000
server: Caddy
date: Sun, 20 Oct 2024 13:51:48 GMT

# Observe the cache was not purged
$ curl -ik https://localhost/souin-api/souin/surrogate_keys
HTTP/2 200 
alt-svc: h3=":443"; ma=2592000
content-type: application/json
server: Caddy
content-length: 592
date: Sun, 20 Oct 2024 13:51:50 GMT

{"GET-https-localhost-/":"\u0004\"M\u0018dp\ufffd\ufffd\u0000\u0000\u0000\ufffd\ufffdHTTP/0.0 200 OK\r\nAlt-Svc: h3=\":443\"; ma=2592000\r\nCache-Control: \r\nContent-Type: text/plain; charset=utf-8\r\nDate: Sun, 20 Oct 2024 13:50:55 GMT\r\nServer: Caddy\r\nX-Souin-Stored-Length: 12\u001b\u0000\ufffd\nTtl: 2m0s\r\n\r\nHello World!","IDX_GET-https-localhost-/":"\nV\n\u0015GET-https-localhost-/\u0012=\n\f\b\ufffd\ufffdԸ\u0006\u0010\ufffd\ufffdԃ\u0003\u0012\n\b\ufffd\ufffdԸ\u0006\u0010\ufffd\ufffd\u0001\u001a\n\b\ufffd\ufffdԸ\u0006\u0010\ufffd\ufffd\u00012\u0015GET-https-localhost-/"}

Note that curl -ik -X PURGE https://localhost/souin-api/souin/flush works. Maybe the fact that flush directly calls DeleteMany could explain the different behavior, but I'm not sure where the bug is coming from. Hope this info can help!

@darkweak
Copy link
Owner

Hey @mac-chaffee thank you for this feedback, I'll embark it in the PR #558.

@darkweak
Copy link
Owner

@mac-chaffee the commit 07d53bf5856586e391da1020e0a59f72dcb52ced should solve your issue:

xcaddy build --with github.com/darkweak/souin/plugins/caddy@07d53bf5856586e391da1020e0a59f72dcb52ced --with github.com/darkweak/souin@07d53bf5856586e391da1020e0a59f72dcb52ced

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants