Why this matters
Avoids repeated CPU/network work on hot paths.
Apply memoization (functools.lru_cache) or explicit caches for pure, expensive computations keyed by inputs.
Avoids repeated CPU/network work on hot paths.
Side-by-side examples engineers can pattern-match during review.
def parse_pattern(p):
return re.compile(p) # compiled every callfrom functools import lru_cache
@lru_cache(maxsize=256)
def parse_pattern(p: str):
return re.compile(p)compute(x) # repeated@lru_cache
def compute(x): ...From the same buckets as this rule.
All static JS/CSS/font/image files MUST use content-hashed filenames (e.g., app.9c1a7b.js) and be served with "Cache-Control: public, max-age=31536000, immutable". HTML and other non-fingerprinted documents MUST be served with "Cache-Control: no-cache" (or equivalent) to enable conditional revalidation.