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 Plugin

Cache Plugin Laravel Package

saloonphp/cache-plugin

Laravel-friendly Saloon plugin that adds transparent response caching to your API requests. Supports configurable cache keys, TTL, and cache stores, helping reduce duplicate calls, speed up apps, and respect rate limits with minimal setup.

View on GitHub
Deep Wiki
Context7

Official plugin for caching Saloon responses

Frequently asked questions about Cache Plugin
How do I install the saloonphp/cache-plugin in a Laravel project?
Run `composer require saloonphp/cache-plugin` and ensure you have a PSR-16 cache driver (e.g., Redis or Memcached) configured in Laravel. The plugin integrates seamlessly with Saloon’s existing middleware pipeline.
Which Laravel versions and Saloon versions does this plugin support?
The plugin requires **Saloon v4+** and **PHP 8.1+**. While Laravel compatibility depends on Saloon’s Laravel integration, it works with Laravel 9+ and 10+ by default, as Saloon supports these versions.
Can I cache responses globally or only per-request?
You can configure caching **globally** via Saloon’s middleware stack or **per-request** using the `withCache()` method. Global caching applies to all requests, while per-request lets you fine-tune TTL and keys dynamically.
What cache backends are supported (Redis, database, etc.)?
The plugin supports **any PSR-16 compliant cache** (Redis, Memcached, APCu, or Laravel’s filesystem cache). Database-based caches require a custom adapter, as they aren’t natively supported.
How do I handle cache invalidation for dynamic API responses?
Use **TTL-based expiration** or implement **event-driven invalidation** (e.g., webhooks or manual cache clearing). For mutable data, combine the plugin with Laravel’s cache tags or a custom invalidation strategy.
What happens if the cache fails during a request?
By default, the plugin **falls back to the original HTTP request** if the cache fails. You can customize this behavior by extending Saloon’s middleware or using a circuit breaker (e.g., `saloonphp/circuit-breaker`).
Is this plugin suitable for real-time APIs like WebSocket push notifications?
No. This plugin is **not recommended** for real-time systems where stale data is unacceptable. It’s optimized for **read-heavy, idempotent APIs** (e.g., product catalogs, weather data) where latency or rate limits are concerns.
How do I test the caching behavior in PHPUnit?
Mock the PSR-16 cache pool using Laravel’s `Mockery` or PHPUnit’s `getMockBuilder()`. Verify cache hits/misses by checking the `CacheItemPoolInterface` interactions. Test edge cases like TTL expiration and cache key collisions.
Are there alternatives to this plugin for caching Saloon responses?
Yes. For simple cases, **Laravel’s built-in HTTP client caching** or **OPcache** (for PHP bytecode) might suffice. For advanced use cases, consider **dedicated reverse proxies (Varnish, Nginx)** or Saloon’s **retry middleware** for rate-limited APIs.
How do I monitor cache performance (hit/miss rates) in production?
Instrument the cache with **Laravel’s cache events** or use **OpenTelemetry** to track cache interactions. Log hit/miss rates via middleware or a dedicated monitoring tool like Datadog or Prometheus.
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.
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge
l3aro/rating-star-for-filament
leek/filament-subtenant-scope