← Webalkalmazás fejlesztők adatlapja
Nézd meg, miben segít
Laravel-teljesítmény és cache
Mért lekérdezési költséget csökkent korlátos adatbetöltéssel és helyesen határolt gyorsítótárral.
laravel-performance-cache
Ezt a skillt használó csapattagok
Mikor hasznos?
Akkor használd, ha adatmennyiséggel lassulnak a listák vagy riportok.
Miben segít neked?
- Megkeresi a tényleges szűk keresztmetszetet és ismételt kapcsolatbetöltést.
- Szükséges mezőket, lapozást és adatbázis-összesítést használ.
- Ügyfelet, jogosultságot és szűrést is figyelembe vesz a cache-ben.
Például ezt kérheted
Optimalizáld a rendelési irányítópultot mérés alapján, és mutasd meg két ügyfél cache-kulcsát és érvénytelenítését. Adminisztrátorként töltsd a gyorsítótárat, majd másik szervezet korlátozott felhasználójaként kérd le. A sorok és összegek kövessék az aktuális jogokat.
Részletes dokumentáció
Itt a skill eredeti útmutatóját, példáit és ellenőrzési szempontjait olvashatod az eredeti nyelven.
Összecsukás
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.
Csomagban lévő fájlok 2
LICENSE.txtSKILL.md
