-
Forward requests to a configurable origin (e.g.,
http://dummyjson.com) -
In-memory caching with
ConcurrentHashMap -
Adds
X-Cacheresponse header: HIT (served from cache) / MISS (fetched and stored) -
CLI flags:
--port,--origin,--clear-cache -
Minimal dependencies, fast startup, easy to extend
-
Start proxy
java -jar target/caching-proxy.jar --port=3000 --origin=http://dummyjson.com
-
Clear cache
java -jar target/caching-proxy.jar --clear-cache
| Flag | Type | Default | Description |
|---|---|---|---|
--port |
int |
3000 |
Port for the proxy server |
--origin |
url |
— |
Origin base URL (e.g., |
--clear-cache |
bool |
false |
Clears in-memory cache and exits |
|
Tip
|
You can also use environment variables (optional) like PROXY_PORT and PROXY_ORIGIN.
|
-
On startup, CLI flags set port & origin.
-
On request:
-
If cached → return cached body with
X-Cache: HIT -
If not cached → forward to origin, store response, return with
X-Cache: MISS
-
-
--clear-cacheempties cache and exits.
Client → Proxy(Server:3000) → Origin
↑ |
└── Cache ─┘
ab -n 200 -c 20 http://localhost:3000/productsCompare first run (MISS heavy) vs repeated run (HIT heavy).
-
❏ TTL / max-size eviction (LRU)
-
❏ Cache policies by method/headers
-
❏ Invalidation endpoint
-
❏ Metrics (Micrometer/Prometheus)
-
❏ Redis as optional persistent backend