🔁
Caching Responses
There are scenarios where you may want to cache a response from an API, like retrieving a static list or retrieving data that you know won't change for a specified amount of time. Caching can be incredibly powerful and can speed up an application by relying less on a third-party integration. Saloon has a first-party plugin that you can install to enable caching support.
To install the caching functionality into Saloon, install the plugin using Composer.
composer require saloonphp/cache-plugin "^2.0"
Next, add the
Cacheable
interface and HasCaching
trait to your request or connector. You must define the two methods.- resolveCacheDriver
- cacheExpiryInSeconds
<?php
use Saloon\CachePlugin\Contracts\Driver;
use Saloon\CachePlugin\Traits\HasCaching;
use Saloon\CachePlugin\Contracts\Cacheable;
class GetServersRequest extends Request implements Cacheable
{
use HasCaching;