PRO

Effect Cache Penetration Shield

The shield for keys that do not exist, which a plain cache cannot protect. A cache only helps for keys that are present, so an attacker iterating random ids misses every time and points the full request rate at the database (the cache-miss attack). A bloom filter seeded with every existing key answers definitely-absent in memory so made-up keys die before the database hears them, and a TTL'd negative cache absorbs repeats for keys that existed then vanished. Index math uses (h >>> 0) so a negative typed-array index can never drop a bloom bit into a false negative. The demo: 50 fake-key requests, 0 database hits. Pinned to effect 4.0.0-beta.98.

Install
npx shadcn@latest add https://ui.aryank.space/r/effect-cache-penetration-shield.json

Installs from ui.aryank.space. To add it by hand, copy the files in Files below, or register the @compronents namespace via the docs.

Visualization
shield
get fakeKey
string
database hits
0
cache.miss -> db.fetch(fakeKey) // 50 db hits

A cache only helps keys that exist. 50 requests for a made-up id all miss, the database confirms nothing, and nothing is cached: every request repeats the full trip.

Files

Dependencies