# 🔁 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](https://github.com/Sammyjo20/saloon-cache-plugin) that you can install to enable caching support. ### Installation To install the caching functionality into Saloon, install the plugin using Composer. ```bash composer require saloonphp/cache-plugin "^3.0" ``` ### Configuration Next, add the `Cacheable` interface and `HasCaching` trait to your request or connector. You must define the two methods. * resolveCacheDriver * cacheExpiryInSeconds ```php send(new GetServersRequest); $response->isCached(); // false // Next time it is sent... $response = $forge->send(new GetServersRequest); $response->isCached(); // true ``` #### When will Saloon cache a request? Saloon will only cache a **successful** request when the method is either GET or OPTIONS. You can customise this by extending the `getCacheableMethods` method where you added the `HasCaching` trait. ```php invalidateCache(); $response = $forge->send($request); ``` ### Temporarily Disabling Caching Sometimes you may wish to disable the caching on a per-request basis for debugging or to bypass caching. You can do this by using the `disableCaching` method on the request. ```php disableCaching(); $response = $forge->send($request); ``` ### Source Code To view the source code of this plugin, [click here](https://github.com/Sammyjo20/saloon-cache-plugin).