Skip to content

Commit a37d862

Browse files
committed
Always serve stale cache, 6M TTL, 5y disk retention, CACHE_STALE_TIME env
- Add 'expired' to proxy_cache_use_stale so expired entries are served immediately while refreshed in the background (fixes MISSes after TTL) - Bump inactive from 365d to 5y so cache files are never purged from disk - Change default CACHE_STALE_TIME from 5d to 6M - Remove unused nginx.conf.template.backup - Update README to document new defaults and behaviour
1 parent be34359 commit a37d862

4 files changed

Lines changed: 14 additions & 134 deletions

File tree

Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ LABEL description="NGINX caching proxy for Owlery"
55

66
ENV UPSTREAM_SERVER=owl.virtualflybrain.org:80
77
ENV CACHE_MAX_SIZE=20g
8+
ENV CACHE_STALE_TIME=6M
89
ENV DNS_RESOLVER=8.8.8.8
910

1011
ARG NGINX_CONF=nginx.conf.template
@@ -17,4 +18,4 @@ RUN mkdir -p /var/cache/nginx/owlery && chown -R nginx:nginx /var/cache/nginx &&
1718

1819
EXPOSE 80 8080
1920

20-
CMD ["/bin/sh", "-c", "export UPSTREAM_SERVER=$UPSTREAM_SERVER && export CACHE_MAX_SIZE=$CACHE_MAX_SIZE && export DNS_RESOLVER=\"$DNS_RESOLVER\" && envsubst '${UPSTREAM_SERVER} ${CACHE_MAX_SIZE} ${DNS_RESOLVER}' < /etc/nginx/nginx.conf.template > /etc/nginx/nginx.conf && /usr/local/bin/health-monitor.sh & nginx -g 'daemon off;'"]
21+
CMD ["/bin/sh", "-c", "export UPSTREAM_SERVER=$UPSTREAM_SERVER && export CACHE_MAX_SIZE=$CACHE_MAX_SIZE && export CACHE_STALE_TIME=$CACHE_STALE_TIME && export DNS_RESOLVER=\"$DNS_RESOLVER\" && envsubst '${UPSTREAM_SERVER} ${CACHE_MAX_SIZE} ${CACHE_STALE_TIME} ${DNS_RESOLVER}' < /etc/nginx/nginx.conf.template > /etc/nginx/nginx.conf && /usr/local/bin/health-monitor.sh & nginx -g 'daemon off;'"]

README.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
[![Docker Image](https://img.shields.io/badge/docker-virtualflybrain%2Fowl_cache-blue)](https://hub.docker.com/r/virtualflybrain/owl_cache)
44

5-
A high-performance caching proxy server that sits in front of OWL reasoning services to dramatically speed up query responses. Built on NGINX Alpine with 90-day cache TTL and stale-while-revalidate pattern.
5+
A high-performance caching proxy server that sits in front of OWL reasoning services to dramatically speed up query responses. Built on NGINX Alpine with a 6-month cache TTL, stale-while-revalidate pattern, and 5-year disk retention so a cached response is always available.
66

77
## Usage Examples
88

@@ -53,7 +53,8 @@ The health endpoint now proxies to the upstream server to verify connectivity. I
5353

5454
- `UPSTREAM_SERVER`: Backend server URL (default: `owl.virtualflybrain.org:80`)
5555
- `CACHE_MAX_SIZE`: Maximum cache size on disk (default: `20g`, accepts NGINX size units like `1t` for 1TB)
56-
- `DNS_RESOLVER`: DNS resolver servers (default: `8.8.8.8 1.1.1.1`, space-separated list). Check `cat /etc/resolv.conf` in your container to find the correct value for your environment.
56+
- `CACHE_STALE_TIME`: How long a cached response is considered fresh (default: `6M`). After this time the entry is served stale while being refreshed in the background. Accepts NGINX time units: `s`, `m`, `h`, `d`, `w`, `M` (30 days), `y` (365 days).
57+
- `DNS_RESOLVER`: DNS resolver servers (default: `8.8.8.8`, space-separated list). Check `cat /etc/resolv.conf` in your container to find the correct value for your environment.
5758

5859
### Cache Headers
5960

@@ -64,7 +65,8 @@ The proxy adds helpful headers to responses:
6465

6566
## Performance
6667

67-
- **Cache TTL**: 90 days for successful responses
68+
- **Cache TTL**: 6 months for successful responses (configurable via `CACHE_STALE_TIME`)
69+
- **Disk retention**: 5 years (`inactive=5y`) — entries are never evicted while disk space allows
6870
- **First request**: ~200ms (backend query)
6971
- **Cached requests**: <10ms (from cache)
7072
- **Cache size**: Up to 20GB on disk (configurable via `CACHE_MAX_SIZE`)
@@ -82,8 +84,9 @@ The proxy adds helpful headers to responses:
8284

8385
### Caching Behavior
8486

85-
- **Cache TTL**: 90 days for HTTP 200, 10 minutes for 404, errors not cached
86-
- **Stale-while-revalidate**: `proxy_cache_use_stale updating` + `proxy_cache_background_update on`
87+
- **Cache TTL**: 6 months for HTTP 200/400, 10 minutes for 404 (TTL configurable via `CACHE_STALE_TIME`)
88+
- **Always serve stale**: `proxy_cache_use_stale expired updating` — expired entries are served immediately while refreshed in the background (prevents MISSes after TTL)
89+
- **Disk retention**: 5 years — cache files are kept on disk even after TTL expires
8790
- **Retry on errors**: Automatically retries failed requests (502, 503, 504, timeouts) up to 2 times
8891
- **Cache lock**: Prevents stampede with `proxy_cache_lock on`
8992
- **Cache key**: `$request_method$request_uri`

nginx.conf.template

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,18 @@ http {
1919
access_log /dev/stdout cache;
2020
error_log /dev/stderr warn;
2121

22-
proxy_cache_path /var/cache/nginx/owlery levels=1:2 keys_zone=owlery_cache:100m max_size=${CACHE_MAX_SIZE} inactive=365d use_temp_path=off;
22+
proxy_cache_path /var/cache/nginx/owlery levels=1:2 keys_zone=owlery_cache:100m max_size=${CACHE_MAX_SIZE} inactive=5y use_temp_path=off;
2323

2424
proxy_cache_key "$request_method$request_uri";
2525
proxy_cache_min_uses 1;
2626
proxy_cache_revalidate on;
2727
proxy_cache_methods GET HEAD;
2828

29-
proxy_cache_valid 200 5d;
30-
proxy_cache_valid 400 5d;
29+
proxy_cache_valid 200 ${CACHE_STALE_TIME};
30+
proxy_cache_valid 400 ${CACHE_STALE_TIME};
3131
proxy_cache_valid 404 600s;
3232

33-
proxy_cache_use_stale error timeout updating http_500 http_502 http_503 http_504 http_404;
33+
proxy_cache_use_stale error timeout expired updating http_500 http_502 http_503 http_504 http_404;
3434
proxy_cache_background_update on;
3535
proxy_cache_lock on;
3636
proxy_cache_lock_timeout 30s;

nginx.conf.template.backup

Lines changed: 0 additions & 124 deletions
This file was deleted.

0 commit comments

Comments
 (0)