spatie/blink
spatie/blink is a tiny in-memory cache for PHP apps. Store values for the current request to avoid repeated work like duplicate queries or expensive calculations. Simple API, no persistence—perfect for per-request memoization in Laravel and beyond.
Install via Composer: composer require spatie/blink. Blink provides an ultra-fast, in-memory cache that persists only for the duration of a single request (or optionally across requests when used with spatie/laravel-blink package). Start by instantiating it directly: $blink = new Spatie\Blink\Blink();, then use put('key', 'value') and get('key') for immediate, zero-I/O caching within a request lifecycle. Ideal for caching expensive operations like repeated DB queries or API calls within the same HTTP request.
Blink::put('user:' . $id, $user); before a deep call, then Blink::get('user:' . $id) later).Blink::store('my-store')->put(...) to share data across service providers, jobs, middleware, and events in one request.Blink::fake(); to assert cache interactions: $this->assertEquals('expected', Blink::get('key'));.put from one class, get in another — avoiding dependency injection of shared state.Blink::store('default')->forever(...) only if using spatie/laravel-blink, but note it writes to the configured cache driver (not truly “blink” speed).forget('key') or clear() to manually prune.Blink::fake(), only the store instance used in fake() is mocked — use Blink::setFakeStoreName('default') to ensure Blink::store() calls are also faked.new Blink()) is slightly faster than static calls (Blink::) due to avoiding __callStatic overhead.How can I help you explore Laravel packages today?