diff --git a/app/Http/Integrations/Spoonacular/Requests/FindRecipesByIngredients.php b/app/Http/Integrations/Spoonacular/Requests/FindRecipesByIngredients.php index a27fc1f..a0cf09e 100644 --- a/app/Http/Integrations/Spoonacular/Requests/FindRecipesByIngredients.php +++ b/app/Http/Integrations/Spoonacular/Requests/FindRecipesByIngredients.php @@ -2,11 +2,18 @@ namespace App\Http\Integrations\Spoonacular\Requests; +use Illuminate\Support\Facades\Cache; +use Saloon\CachePlugin\Contracts\Cacheable; +use Saloon\CachePlugin\Contracts\Driver; +use Saloon\CachePlugin\Drivers\LaravelCacheDriver; +use Saloon\CachePlugin\Traits\HasCaching; use Saloon\Enums\Method; use Saloon\Http\Request; -class FindRecipesByIngredients extends Request +class FindRecipesByIngredients extends Request implements Cacheable { + use HasCaching; + /** * The HTTP method of the request */ @@ -36,4 +43,14 @@ class FindRecipesByIngredients extends Request 'number' => $this->number, ]; } + + public function resolveCacheDriver(): Driver + { + return new LaravelCacheDriver(Cache::store('redis')); + } + + public function cacheExpiryInSeconds(): int + { + return 3600; + } } diff --git a/composer.json b/composer.json index 65d27b9..73163e4 100644 --- a/composer.json +++ b/composer.json @@ -10,6 +10,7 @@ "laravel/framework": "^11.9", "laravel/sanctum": "^4.0", "laravel/tinker": "^2.9", + "saloonphp/cache-plugin": "^3.0", "saloonphp/laravel-plugin": "^3.0", "saloonphp/saloon": "^3.0", "tightenco/ziggy": "^2.0" diff --git a/composer.lock b/composer.lock index 20ed736..afcae69 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "81d14f9724514fae3a05d53d66d9ed8a", + "content-hash": "66624b5874af1460670a10f2295eb049", "packages": [ { "name": "brick/math", @@ -3247,6 +3247,56 @@ ], "time": "2024-04-27T21:32:50+00:00" }, + { + "name": "saloonphp/cache-plugin", + "version": "v3.0.0", + "source": { + "type": "git", + "url": "https://github.com/saloonphp/cache-plugin.git", + "reference": "9ed8efd0e08902ee105249c4d8d55edc0e8dc864" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/saloonphp/cache-plugin/zipball/9ed8efd0e08902ee105249c4d8d55edc0e8dc864", + "reference": "9ed8efd0e08902ee105249c4d8d55edc0e8dc864", + "shasum": "" + }, + "require": { + "php": "^8.1", + "saloonphp/saloon": "^3.0" + }, + "require-dev": { + "friendsofphp/php-cs-fixer": "^3.13", + "league/flysystem": "^3.12.2", + "orchestra/testbench": "^8.0", + "pestphp/pest": "^2.3", + "psr/simple-cache": "^3.0", + "spatie/ray": "^1.34.2" + }, + "type": "library", + "autoload": { + "psr-4": { + "Saloon\\CachePlugin\\": "src/", + "Saloon\\CachePlugin\\Tests\\": "tests/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Sammyjo20", + "email": "29132017+Sammyjo20@users.noreply.github.com" + } + ], + "description": "Official plugin for caching Saloon responses", + "support": { + "issues": "https://github.com/saloonphp/cache-plugin/issues", + "source": "https://github.com/saloonphp/cache-plugin/tree/v3.0.0" + }, + "time": "2023-10-02T16:29:40+00:00" + }, { "name": "saloonphp/laravel-plugin", "version": "v3.5.0",