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

desarrolla2/cache

Immutable PSR-16 simple cache library for PHP with multiple adapters (APCu, File, Memcached, Redis, MongoDB, etc.) plus a Chain adapter. Supports configurable options like default TTL via withOption/withOptions. Aims to be complete, correct, and fast.

View on GitHub
Deep Wiki
Context7

A simple cache library. Implements different adapters that you can use and change easily by a manager or similar.

Frequently asked questions about Cache
How do I integrate desarrolla2/cache with Laravel’s existing Cache facade?
Replace Laravel’s default CacheManager by binding the package’s CacheManager in a service provider. Use `Cache::store('redis')->get()` syntax, but delegate to the package’s adapters. Ensure your adapters (e.g., Predis for Redis) are PSR-16 compliant and properly configured in Laravel’s `config/cache.php`.
Does this package support Laravel 10+ and PHP 8.x?
No, the package hasn’t been updated since 2018 and may not support PHP 8.x features like named arguments or Laravel 10+. You’d need to fork and modernize it or use Laravel’s native cache drivers for compatibility. Test thoroughly if adopting in production.
Can I use this for multi-tier caching (e.g., Redis + file fallback)?
Yes, the package’s Chain adapter lets you combine multiple backends (e.g., Redis primary, file fallback). Configure it via `Cache::store('chain')->get()` and define the chain order in your service provider. This is useful for high-availability setups.
What’s the performance impact compared to Laravel’s native cache?
The package adds abstraction overhead, so benchmarks are recommended. Laravel’s native drivers (e.g., Redis via Predis) are often optimized for performance. Use this only if you need custom logic (e.g., dynamic adapter switching) or legacy system support.
How do I configure TTL and other options immutably?
Use `withOption()` or `withOptions()` to create a new cache instance with updated settings. For example, `$cache->withOption('ttl', 7200)` returns a new instance with a 2-hour default TTL. Immutability prevents side effects across your application.
Are there built-in Artisan commands for cache management?
No, the package lacks CLI tools. Use Laravel’s native `cache:clear` or `cache:table` commands for standard operations. For custom adapters, create wrapper commands in your service provider or use the package’s API directly in console scripts.
What if I need MongoDB or MySQL caching beyond Laravel’s defaults?
The package includes MongoDB and MySQL (mysqli) adapters, but they may not match Laravel’s native drivers in features (e.g., tags, events). Test thoroughly for your use case, as these adapters are lower-level and require manual configuration.
How do I mock this package in PHPUnit tests?
Use PHPUnit’s mock builder to replace the `CacheInterface` in tests. The adapter pattern makes it easy to isolate cache logic. For example, mock `get()`/`set()` methods on the adapter instance injected into your service or repository.
What are the risks of using a stagnant package in production?
Stagnation risks include compatibility issues with PHP/Laravel updates, unpatched security vulnerabilities in underlying adapters (e.g., Redis), and lack of community support. Mitigate by forking, modernizing, or using it only for non-critical caching layers.
Can I dynamically switch cache adapters at runtime?
Yes, leverage the package’s adapter pattern and Laravel’s service container. Bind multiple adapters (e.g., Redis, Memcached) and switch them via `Cache::store('dynamic_adapter')->get()`, where the adapter is resolved dynamically based on runtime conditions.
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.
terminal42/code-quality-tools
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky