Skip to content

Commit f89bb29

Browse files
adiologydevclaude
andcommitted
docs: document cache modes and security settings
Update README and .env.example with: - Cache mode descriptions (disk, memory, hybrid, none) - Security settings table (ALLOWED_DOMAINS, ALLOWED_ORIGINS) - Production configuration example 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent d965397 commit f89bb29

2 files changed

Lines changed: 41 additions & 4 deletions

File tree

.env.example

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,23 @@
22
PORT=3000
33

44
# Cache settings
5-
CACHE_MODE=disk # Cache mode: "disk" | "memory" | "none" (default: disk)
6-
CACHE_DIR=./cache # Directory for disk cache (only used when CACHE_MODE=disk)
5+
# Cache modes:
6+
# disk - Persist to disk only (survives restarts)
7+
# memory - In-memory only (fastest, lost on restart)
8+
# hybrid - Memory (L1) + Disk (L2) for speed and persistence
9+
# none - No caching
10+
CACHE_MODE=disk
11+
CACHE_DIR=./cache # Directory for disk cache (disk/hybrid modes)
712
CACHE_TTL=86400 # Cache TTL in seconds (default: 24 hours)
813
MAX_CACHE_SIZE=1073741824 # Max cache size in bytes (default: 1GB, disk mode only)
9-
MAX_MEMORY_CACHE_ITEMS=1000 # Max items in memory cache (default: 1000, memory mode only)
14+
MAX_MEMORY_CACHE_ITEMS=1000 # Max items in memory cache (memory/hybrid modes)
1015
BROWSER_CACHE_TTL=31536000 # Browser cache TTL in seconds (default: 1 year)
1116

1217
# Security
13-
ALLOWED_DOMAINS= # Comma-separated list of allowed domains (empty = allow all)
18+
ALLOWED_DOMAINS= # Comma-separated source image domains (empty = allow all)
19+
# Example: example.com,cdn.example.com
20+
ALLOWED_ORIGINS= # Comma-separated CORS origins (empty = allow all)
21+
# Example: https://example.com,https://app.example.com
1422
MAX_IMAGE_SIZE=10485760 # Max image size in bytes (default: 10MB)
1523
REQUEST_TIMEOUT=30000 # Request timeout in ms (default: 30s)
1624

README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,35 @@ BROWSER_CACHE_TTL=31536000 # 1 year
250250
TEMPLATES_DIR=./templates
251251
```
252252

253+
### Cache Modes
254+
255+
| Mode | Description |
256+
| -------- | --------------------------------------------------------------------------- |
257+
| `disk` | Persist to disk only. Survives restarts but slower reads. |
258+
| `memory` | In-memory LRU cache. Fastest but lost on restart. |
259+
| `hybrid` | Memory (L1) + Disk (L2). Fast reads with persistence. Best for production. |
260+
| `none` | No caching. Every request processes the image fresh. |
261+
262+
### Security Settings
263+
264+
| Variable | Description |
265+
| ----------------- | ----------------------------------------------------------------------------------------------------- |
266+
| `ALLOWED_DOMAINS` | Restricts which domains can be used as image sources. Supports subdomains (e.g., `example.com` allows `cdn.example.com`). |
267+
| `ALLOWED_ORIGINS` | Restricts which origins can make CORS requests. Use full URLs (e.g., `https://example.com`). |
268+
269+
**Example configuration for production:**
270+
271+
```bash
272+
# Only allow fetching images from your domain
273+
ALLOWED_DOMAINS=example.com
274+
275+
# Only allow your frontend to make requests
276+
ALLOWED_ORIGINS=https://example.com,https://app.example.com
277+
278+
# Use hybrid cache for best performance
279+
CACHE_MODE=hybrid
280+
```
281+
253282
## Custom Templates
254283

255284
Create JSON template files in the `templates/` directory:

0 commit comments

Comments
 (0)