Why this matters
Avoids repeated heavy queries, improving latency and DB load.
Cache frequently used, rarely changing query results in memory or an external cache with appropriate TTL/invalidations.
Avoids repeated heavy queries, improving latency and DB load.
Side-by-side examples engineers can pattern-match during review.
function categories(){ return $pdo->query('SELECT * FROM categories')->fetchAll(); }function categories(Cache $cache, PDO $pdo){
return $cache->remember('categories', 300, function() use ($pdo){
return $pdo->query('SELECT * FROM categories')->fetchAll(PDO::FETCH_ASSOC);
});
}always query SELECT *$cache->remember('key', ttl, fn() => query())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.
Serve text-based assets (JS, CSS, JSON, SVG) with Brotli (br) when the client sends "Accept-Encoding: br" and fallback to gzip. Always set "Vary: Accept-Encoding" and do NOT compress already-compressed formats (e.g., .png, .jpg, .woff2).