← Zurück zu Web-App-Entwickler
Entdecke, wie der Skill hilft
Laravel-Leistung und Cache
Verringert gemessene Abfragekosten mit begrenztem Laden und korrekt abgegrenzten Cacheeinträgen.
laravel-performance-cache
Teammitglieder mit diesem Skill
Wann ist der Skill hilfreich?
Nutze diesen Skill bei mitwachsend langsamen Listen oder Berichten.
Wobei hilft er dir?
- Findet reale Engpässe und wiederholtes Laden von Beziehungen.
- Nutzt benötigte Spalten, Seitennavigation und Datenbankaggregate.
- Berücksichtigt Mandant, Rechte und Filter bei Cachekennung und Invalidierung.
Das könntest du fragen
Optimiere unser Bestelldashboard anhand von Abfragen und erkläre Cachekeys sowie Invalidierung für zwei unterschiedliche Mandanten. Fülle den Cache als Administrator und lade ihn als eingeschränkter Nutzer eines anderen Mandanten. Zwischengespeicherte Summen und Zeilen wahren dessen Rechte.
Ausführliche Dokumentation
Hier findest du die ursprüngliche Anleitung, Beispiele und Prüfschritte des Skills in ihrer Originalsprache.
Weniger anzeigen
Laravel Performance & Cache
Measure first, then eliminate N+1 and over-fetching
- Gather concrete evidence before optimizing: inspect executed queries (
DB::listen,assertQueryCount, Debugbar/Telescope logs orEXPLAIN) to identify the actual bottleneck. - Eager load every relationship accessed in loops, Blade views or API Resources (
with(['author:id,name', 'comments.user'])). When constraining columns on an eager load, always include the primary key (id) and foreign key (user_id) or Eloquent cannot link the models. - Respect
Model::preventLazyLoading()if enabled in the project. - Select only needed columns (
select(['id', 'title', 'created_at'])), and avoid loadingTEXT/BLOBcolumns on list endpoints. - Paginate list endpoints (
paginate(),simplePaginate()orcursorPaginate()for deep pages). Never return unboundedModel::all()or->get()results on growing tables. - Use
exists()/doesntExist()instead ofcount() > 0, andwithCount()/withSum()/withAvg()instead of loading full relation collections just to count or sum them.
Caching and key hygiene
- Use
Cache::remember($key, $ttl, fn () => ...)orCache::flexible($key, [$fresh, $stale], fn () => ...)(Laravel 11.23+) for expensive, read-heavy queries, andCache::memo()(Laravel 12+) when repeating reads within a single request. - Scope every cache key with a clear prefix and all parameters that affect the output: tenant/organization ID, user/role context, locale, filters and page (
"tenant:{$tenantId}:user:{$userId}:stats"). Never share a cache key across tenants or permission levels. - Pair every cached value with an explicit TTL and invalidation strategy (
Cache::forget(...)on model writes/events or cache tags on Redis/Memcached). - Never use caching to mask broken authorization, inconsistent state or an easily fixed N+1 query, and never flush production caches without explicit authorization.
Enthaltene Dateien 2
LICENSE.txtSKILL.md
