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

Cache Laravel Package

illuminate/cache

View on GitHub
Deep Wiki
Context7

Getting Started

Begin by installing via Composer: composer require illuminate/cache. Then configure the cache store using Laravel's config/cache.php (if using full Laravel) or manually instantiate the CacheManager and provide a Repository with a configured store (e.g., ArrayStore, FileStore, RedisStore). For initial exploration, use the ArrayStore in memory—it’s zero-configuration and ideal for testing. First use case: caching the result of an expensive function with Cache::remember('key', $ttl, fn() => expensiveOperation()).

Implementation Patterns

  • Tagged caching: Use Cache::tags(['users', 'posts'])->remember('users:1', $ttl, ...), though note tag support is limited to TaggedCache implementations (e.g., Redis, Memcached).
  • Cacheable value objects: Store Eloquent models or DTOs directly; the package handles serialization via Symfony Serializer or similar.
  • Rate limiting & locks: Use Cache::lock('name', $timeout) for distributed locking, and combine with Cache::pull('token') for one-time consumption (e.g., OAuth callbacks).
  • Custom store adapters: Implement Illuminate\Contracts\Cache\Store for niche persistence layers (e.g., DynamoDB, custom DB table).
  • Centralized cache helper: Wrap Cache::() calls in a service class to enable mocking in tests and consistent TTL/key naming (e.g., App\Services\ArticleCache::getLatest()).

Gotchas and Tips

  • Serialization pitfalls: Boolean null vs false distinction matters—Cache::put('key', false) stores false, but Cache::remember('key', $ttl, fn() => null) stores null; ensure your retrieval logic doesn’t conflate missing keys with falsy values.
  • In-memory vs persistent: ArrayStore resets on each request—never use it in production. Default file store serializes entries but doesn’t auto-detect Laravel’s CACHE_DRIVER unless using the CacheManager.
  • Tag limitations: Tags only work with supported stores; using FileStore with tags() silently ignores tags or throws if the underlying TaggedCache isn’t properly constructed.
  • TTL edge cases: 0 or null TTL means “forever” in most stores, but ArrayStore ignores TTL entirely. Use Carbon::now()->addMinutes(5) instead of raw seconds to avoid confusion.
  • Debugging tip: Enable cache event logging (Cache::listen(fn($event) => logger($event))) to trace misses, hits, and key collisions. Check storage/logs/cache.log for failed writes (e.g., permission issues on storage/framework/cache).
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.
nexmo/api-specification
capell-app/block-library
axium/identity
cetria/laravel-dummy-models
cetria/reflection-helper
agropredict/sso-auth-bundle
evolvestudio/spam-protection
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
ecotone/kafka
22h/doctrine-garbage-collection-bundle
agtp/agtp-php
agtp/mod-php
splash/sonata-admin
splash/metadata