lc-cache-opportunities
Detect repeated queries and computations that should be cached.
Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
メニュー
Detect repeated queries and computations that should be cached.
Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
SOC 職業分類に基づく
Create a Larascraper scraper (v2 or v3) for a target website, chaining browser actions (click, type, wait, scroll), conditional flow (when/repeatUntil), captcha solving, and file/PDF downloads. Detects the installed major and generates the matching style.
Add or edit a Laracrate file collection in config/laracrate.php with the correct anatomy (disk, access, types, variants, previews, extract/embed, flags, per-model scoping).
Runtime-verified Laravel inspection using the Laravel Boost MCP server (Tinker, Database Query/Schema, Last Error) instead of static grep. Falls back to Docker/Tinker if Boost is not installed.
Scaffold spatie/laravel-permission setup - add the HasRoles trait to a model and generate a roles & permissions seeder.
Audit spatie/laravel-permission usage - permissions used in code but undefined, defined but unused, unprotected routes, guard mismatches, and cache pitfalls.
Extract business logic from a controller or Livewire component method into a Laractions Action class.
| name | lc:cache-opportunities |
| description | Detect repeated queries and computations that should be cached. |
| argument-hint | [analyze | fix | fix --dry-run | file-path | fix file-path] |
| user-invocable | true |
| allowed-tools | Read Grep Bash Edit Write Glob |
Detect repeated queries, expensive computations, and external API calls that would benefit from caching. Suggests appropriate caching strategies with TTL values.
| Subcommand | Description |
|---|---|
| (no argument) | Scan the entire project for caching opportunities. Read-only report. |
fix | Wrap detected queries/computations in Cache::remember(). Asks for confirmation before each change. |
fix --dry-run | Show what caching code would be added without changing anything. |
[file-path] | Analyze a specific file for caching opportunities. Read-only. |
fix [file-path] | Add caching to a specific file, with confirmation. |
What to detect:
Setting::get('key') or Config::get() from database tables called multiple timesHow to scan:
Grep to find patterns like Setting::, ->settings, config( calls that query the DB.Read to check if these calls are in frequently-executed code paths (controllers, middleware, Blade views).Suggested TTL: 60-300 seconds (settings change infrequently)
Fix:
// Before
$settings = Setting::where('organization_id', $orgId)->get();
// After
$settings = Cache::remember("org_settings_{$orgId}", 300, function () use ($orgId) {
return Setting::where('organization_id', $orgId)->get();
});
What to detect:
->count(), ->sum(), ->avg() queries used in dashboards or navigation badgeswithCount() on large collections for display-only purposesHow to scan:
Grep to find ->count(), ->sum(), ->avg(), ->max(), ->min() calls.Suggested TTL: 60-120 seconds (acceptable staleness for counters)
Fix:
// Before
$propertyCount = Property::where('organization_id', $orgId)->count();
// After
$propertyCount = Cache::remember("property_count_{$orgId}", 120, function () use ($orgId) {
return Property::where('organization_id', $orgId)->count();
});
What to detect:
Http::get(), Http::post(), curl, Guzzle) without surrounding cacheHow to scan:
Grep to find Http::get(, Http::post(, file_get_contents(http, and similar patterns.Read to check if the call is already wrapped in Cache::remember().Suggested TTL: 300-3600 seconds (depending on data freshness needs)
Fix:
// Before
$response = Http::get("https://api.example.com/data/{$id}");
// After
$response = Cache::remember("api_data_{$id}", 3600, function () use ($id) {
return Http::get("https://api.example.com/data/{$id}")->json();
});
What to detect:
@php blocks or inline PHP->filter()->map()->sort() chains in viewsHow to scan:
Grep to find @php blocks and <?php tags in Blade files.Read to check for query builder calls, complex collection operations, or math computations.Suggested fix: Move computation to the controller/component and cache the result there.
What to detect:
How to scan:
Grep to find similar query patterns across multiple Livewire components.Suggested fix: Use Cache::remember() with a shared cache key, or use Livewire's #[Computed] attribute for component-level caching.
CACHING OPPORTUNITIES
======================
HIGH IMPACT
------------
1. Dashboard statistics (called on every page load)
File: app/Http/Controllers/DashboardController.php:25-40
Queries: 5 aggregate queries (count, sum) on large tables
Frequency: Every request to /dashboard
Suggested TTL: 120 seconds
Estimated savings: ~500ms per request
2. Organization settings (loaded 3x per request)
Files:
- app/Http/Middleware/LoadOrganization.php:18
- resources/views/livewire/layout/navigation.blade.php:8
- resources/views/livewire/layout/sidebar.blade.php:12
Suggested TTL: 300 seconds
Estimated savings: ~100ms per request
MEDIUM IMPACT
--------------
1. External geocoding API call
File: app/Services/GeocodingService.php:42
Current: Http::get() on every property save
Suggested TTL: 86400 seconds (24 hours, addresses rarely change)
LOW IMPACT
-----------
1. User notification count
File: resources/views/livewire/layout/dropdowns/notifications.blade.php:5
Note: Already uses polling (4s), adding cache would reduce DB load
SUMMARY
========
High impact opportunities: 3
Medium impact opportunities: 4
Low impact opportunities: 2
Estimated total savings: ~800ms per request
For each caching opportunity, wrap the target code in Cache::remember():
"org_{$orgId}_property_count").use Illuminate\Support\Facades\Cache; is imported.Cache::remember() call.Each change requires explicit user confirmation.
Show the before/after code for each proposed caching change, with the cache key and TTL that would be used.
Cache::forget() should be called when data changes.config/cache.php for the driver.#[Computed] attribute for component-level caching.