Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Blink Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Getting Started

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.

Implementation Patterns

  • In-request caching: Avoid redundant expensive operations in loops or nested calls (e.g., Blink::put('user:' . $id, $user); before a deep call, then Blink::get('user:' . $id) later).
  • Laravel integration: Use Blink::store('my-store')->put(...) to share data across service providers, jobs, middleware, and events in one request.
  • Testing with fakes: In tests, wrap logic in Blink::fake(); to assert cache interactions: $this->assertEquals('expected', Blink::get('key'));.
  • Per-request state buses: Use Blink as a lightweight message bus — put from one class, get in another — avoiding dependency injection of shared state.

Gotchas and Tips

  • No cross-request persistence: Blink does not persist between requests by default. For global caching (e.g., across workers), combine with Laravel’s cache drivers via Blink::store('default')->forever(...) only if using spatie/laravel-blink, but note it writes to the configured cache driver (not truly “blink” speed).
  • Memory concerns: Avoid caching large arrays or objects in long-running processes (e.g., queues, Horizon workers) — data accumulates for the entire request lifetime. Use forget('key') or clear() to manually prune.
  • Testing nuance: When using Blink::fake(), only the store instance used in fake() is mocked — use Blink::setFakeStoreName('default') to ensure Blink::store() calls are also faked.
  • Performance edge cases: For ultra-low-latency needs (e.g., inner loops), direct instantiation (new Blink()) is slightly faster than static calls (Blink::) due to avoiding __callStatic overhead.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport