Token导航 LogoToken导航TokenDH.com
研究检索需要联网github未标认证来源可访问许可证需确认审计通过

laravel-caching-strategiesLaravel caching strategies 搜索

Agent Skill

laravel-caching-strategies 用于查找、检索和筛选相关信息,适合在 Codex、Claude、Cursor、Gemini CLI 中需要根据关键词、任务场景或来源线索快速定位候选结果时使用。可结合来源仓库、安装命令和原始 README 继续核验具体用法。安装前建议确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写。

总安装

745

周安装

32

GitHub Stars

35

下载量

261
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

2

许可证

unknown

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:laravel-caching-strategies(Laravel caching strategies 搜索)
来源仓库:https://github.com/iserter/laravel-claude-agents
仓库路径:skills/laravel-caching-strategies
安装命令:
npx skills add https://github.com/iserter/laravel-claude-agents --skill laravel-caching-strategies
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/iserter/laravel-claude-agents --skill laravel-caching-strategies

简介

laravel-caching-strategies 用于查找、检索和筛选相关信息,适合在 Codex、Claude、Cursor、Gemini CLI 中需要根据关键词、任务场景或来源线索快速定位候选结果时使用。

  • 适用于需要快速定位候选结果的场景,如根据关键词、任务或来源线索进行信息检索。
  • 通过 npx skills add 命令从 GitHub 仓库安装,需确认权限范围和维护状态。
  • 安装前建议确认是否会触发联网、命令执行或文件读写等操作。
  • 可结合来源仓库和原始 README 继续核验具体用法和功能细节。

SKILL.md

Laravel Caching Strategies

Core Cache Patterns

use Illuminate\Support\Facades\Cache;

// ✅ remember - cache for a duration
$users = Cache::remember('users:active', now()->addMinutes(30), function () {
    return User::where('active', true)->get();
});

// ✅ rememberForever - cache until manually cleared
$settings = Cache::rememberForever('app:settings', function () {
    return Setting::all()->pluck('value', 'key');
});

// ✅ flexible - stale-while-revalidate pattern
// Fresh for 5 min, serves stale for up to 15 min while revalidating in background
$stats = Cache::flexible('dashboard:stats', [300, 900], function () {
    return DashboardStats::calculate();
});

// ✅ put / get / forget
Cache::put('key', $value, now()->addHours(1));
$value = Cache::get('key', 'default');
Cache::forget('key');

// ❌ Querying the database when cache would suffice
$settings = Setting::all(); // Every request hits the DB

Cache Tags for Grouped Invalidation

// ✅ Tag related cache entries
Cache::tags(['posts', 'users'])->put("user:{$userId}:posts", $posts, 3600);
Cache::tags(['posts'])->put("post:{$postId}", $post, 3600);
Cache::tags(['users'])->put("user:{$userId}:profile", $profile, 3600);

// ✅ Flush all caches for a tag group
Cache::tags(['posts'])->flush(); // Clears all post-related caches

// ✅ Retrieve tagged cache
$posts = Cache::tags(['posts', 'users'])->get("user:{$userId}:posts");

// Note: Cache tags are only supported by redis and memcached drivers

Atomic Locks

use Illuminate\Support\Facades\Cache;

// ✅ Prevent concurrent execution
$lock = Cache::lock('processing:order:' . $orderId, 10); // 10 second lock

if ($lock->get()) {
    try {
        // Process order exclusively
        $this->processOrder($orderId);
    } finally {
        $lock->release();
    }
}

// ✅ Block and wait for lock (up to 5 seconds)
$lock = Cache::lock('report:generate', 30);

$lock->block(5, function () {
    // Acquired lock, do work
    $this->generateReport();
}); // Lock auto-released after closure

// ✅ Cross-process lock with owner token
$lock = Cache::lock('deployment', 120);

if ($lock->get()) {
    $owner = $lock->owner();
    // Pass $owner to another process
}

// In the other process
Cache::restoreLock('deployment', $owner)->release();

// ❌ Forgetting to release locks
$lock->get();
$this->doWork(); // If this throws, lock is never released

Cache Memoization

use Illuminate\Support\Facades\Cache;

// ✅ memo - in-memory cache for the current request lifecycle
// Avoids repeated cache store lookups within the same request
$config = Cache::memo('app:config', function () {
    return Config::loadFromDatabase();
});

// Subsequent calls return the in-memory value without hitting Redis/Memcached
$config = Cache::memo('app:config', fn () => Config::loadFromDatabase());

Model Caching Patterns

class Product extends Model
{
    // ✅ Cache on read with automatic invalidation
    public static function findCached(int $id): ?self
    {
        return Cache::remember(
            "product:{$id}",
            now()->addHour(),
            fn () => static::find($id)
        );
    }

    // ✅ Invalidate cache on model changes
    protected static function booted(): void
    {
        static::saved(function (Product $product) {
            Cache::forget("product:{$product->id}");
            Cache::tags(['products'])->flush();
        });

        static::deleted(function (Product $product) {
            Cache::forget("product:{$product->id}");
            Cache::tags(['products'])->flush();
        });
    }
}

// ✅ Cache query results with tags for group invalidation
class ProductService
{
    public function getFeatured(): Collection
    {
        return Cache::tags(['products'])->remember(
            'products:featured',
            now()->addMinutes(30),
            fn () => Product::where('featured', true)->with('category')->get()
        );
    }
}

Cache Key Conventions

// ✅ Use consistent, descriptive key patterns
"user:{$userId}:profile"
"post:{$postId}:comments:page:{$page}"
"tenant:{$tenantId}:settings"
"api:github:repos:{$username}"
"report:daily:{$date}"

// ✅ Include cache-busting identifiers when data shape changes
"v2:user:{$userId}:profile"

// ❌ Vague or collision-prone keys
"data"
"user"
"temp"
"cache_1"

Common Pitfalls

// ❌ Caching null results without handling them
$user = Cache::remember("user:{$id}", 3600, fn () => User::find($id));
// If user doesn't exist, null is cached for an hour

// ✅ Handle null explicitly
$user = Cache::remember("user:{$id}", 3600, function () use ($id) {
    return User::find($id) ?? new NullUser();
});

// ❌ No invalidation strategy
Cache::forever('products:all', Product::all());
// Data becomes stale with no way to refresh

// ✅ Use TTL or event-based invalidation
Cache::remember('products:all', now()->addMinutes(15), fn () => Product::all());

// ❌ Caching too aggressively (serialization cost > query cost)
Cache::remember('user:count', 3600, fn () => User::count());
// Simple COUNT queries are often fast enough without caching

// ✅ Cache expensive operations
Cache::remember('dashboard:analytics', 3600, function () {
    return DB::table('orders')
        ->selectRaw('DATE(created_at) as date, SUM(total) as revenue')
        ->groupByRaw('DATE(created_at)')
        ->orderBy('date')
        ->get();
});

// ❌ Cache stampede - many requests regenerate cache simultaneously
// ✅ Use flexible() for stale-while-revalidate or atomic locks for regeneration

Checklist

  • remember/rememberForever used instead of manual get/put
  • flexible() used for high-traffic keys that tolerate brief staleness
  • Cache tags used for grouped invalidation (Redis/Memcached only)
  • Atomic locks used for exclusive operations
  • Model caches invalidated on save/delete events
  • Cache keys follow a consistent naming convention
  • TTLs set appropriately (not too long, not too short)
  • Null/empty results handled to avoid caching nothing
  • Expensive queries cached, trivial queries left uncached
  • Cache stampede prevented with flexible() or locks

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Codex

33.93%
按下载量换算89

Claude

30.56%
按下载量换算80

Cursor

18.24%
按下载量换算48

Gemini CLI

8.3%
按下载量换算22

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

需要联网

该 Skill 可能需要联网访问来源站点、仓库或外部 API;具体网络访问范围需要结合源码和 README 复核。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。当前只有一个来源,正式发布前建议补源仓库或其他目录站核验。

来源信息

继续浏览同类 Skills