← Back to Laravel and React foundation team
See how it helps
Laravel performance and caching
Improves measured database and response costs with bounded queries and correctly scoped cache entries.
laravel-performance-cache
Team members using this skill
When is it useful?
Use when Laravel list pages or reports become slow as data grows.
What does it help you do?
- Finds actual query bottlenecks and removes repeated relationship loading.
- Selects needed columns, pagination and database aggregates.
- Includes tenant, permissions and filters in cache identity with suitable invalidation.
Try asking this
Optimize our order dashboard using query evidence, then show cache keys and invalidation for two tenants with different permissions. Warm the cache as an administrator, then load it as a restricted user in another tenant. Cached totals and rows must still respect their permissions.
Detailed documentation
Read the skill’s original instructions, examples and checks in their authored language.
Show less
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.
Included files 2
LICENSE.txtSKILL.md
