diff --git a/app/Http/Kernel.php b/app/Http/Kernel.php index ecf02526a..ea9b7ff87 100755 --- a/app/Http/Kernel.php +++ b/app/Http/Kernel.php @@ -36,6 +36,7 @@ class Kernel extends HttpKernel \Illuminate\View\Middleware\ShareErrorsFromSession::class, \App\Http\Middleware\VerifyCsrfToken::class, \Illuminate\Routing\Middleware\SubstituteBindings::class, + ], 'api' => [ @@ -63,5 +64,6 @@ class Kernel extends HttpKernel 'signed' => \Illuminate\Routing\Middleware\ValidateSignature::class, 'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class, 'cart.merger' => \Webkul\Checkout\Http\Middleware\CartMerger::class, + 'cacheResponse' => \Spatie\ResponseCache\Middlewares\CacheResponse::class, ]; } diff --git a/composer.json b/composer.json index 2f32434e6..81e7f38e3 100644 --- a/composer.json +++ b/composer.json @@ -38,6 +38,7 @@ "prettus/l5-repository": "^2.6", "pusher/pusher-php-server": "^7.0", "spatie/laravel-ignition": "^1.0", + "spatie/laravel-responsecache": "^7.4", "spatie/laravel-sitemap": "^6.1" }, "require-dev": { diff --git a/composer.lock b/composer.lock index dbaa8eeeb..53b09fe82 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": "18ab24101a20f1d7f7b4c81ea30dc455", + "content-hash": "ee34f4e708047098e130a18ac9288734", "packages": [ { "name": "astrotomic/laravel-translatable", @@ -7334,6 +7334,89 @@ ], "time": "2022-06-28T14:29:26+00:00" }, + { + "name": "spatie/laravel-responsecache", + "version": "7.4.3", + "source": { + "type": "git", + "url": "https://github.com/spatie/laravel-responsecache.git", + "reference": "59b28a5898da23a44e0a1b0be83db253733a8f86" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/spatie/laravel-responsecache/zipball/59b28a5898da23a44e0a1b0be83db253733a8f86", + "reference": "59b28a5898da23a44e0a1b0be83db253733a8f86", + "shasum": "" + }, + "require": { + "illuminate/cache": "^8.71|^9.0", + "illuminate/console": "^8.71|^9.0", + "illuminate/container": "^8.71|^9.0", + "illuminate/http": "^8.71|^9.0", + "illuminate/support": "^8.71|^9.0", + "nesbot/carbon": "^2.35", + "php": "^8.0", + "spatie/laravel-package-tools": "^1.9" + }, + "require-dev": { + "laravel/framework": "^9.0", + "mockery/mockery": "^1.4", + "orchestra/testbench": "^6.23|^7.0", + "phpunit/phpunit": "^9.4" + }, + "type": "library", + "extra": { + "laravel": { + "providers": [ + "Spatie\\ResponseCache\\ResponseCacheServiceProvider" + ], + "aliases": { + "ResponseCache": "Spatie\\ResponseCache\\Facades\\ResponseCache" + } + } + }, + "autoload": { + "psr-4": { + "Spatie\\ResponseCache\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Freek Van der Herten", + "email": "freek@spatie.be", + "homepage": "https://spatie.be", + "role": "Developer" + } + ], + "description": "Speed up a Laravel application by caching the entire response", + "homepage": "https://github.com/spatie/laravel-responsecache", + "keywords": [ + "cache", + "laravel", + "laravel-responsecache", + "performance", + "response", + "spatie" + ], + "support": { + "source": "https://github.com/spatie/laravel-responsecache/tree/7.4.3" + }, + "funding": [ + { + "url": "https://spatie.be/open-source/support-us", + "type": "custom" + }, + { + "url": "https://github.com/spatie", + "type": "github" + } + ], + "time": "2022-09-24T12:15:10+00:00" + }, { "name": "spatie/laravel-sitemap", "version": "6.2.0", diff --git a/config/cache.php b/config/cache.php index b9a15a17e..5ff076e5c 100755 --- a/config/cache.php +++ b/config/cache.php @@ -15,7 +15,7 @@ return [ | */ - 'default' => env('CACHE_DRIVER', 'file'), + 'default' => env('CACHE_DRIVER', 'redis'), /* |-------------------------------------------------------------------------- @@ -72,7 +72,7 @@ return [ 'driver' => 'redis', 'connection' => env('CACHE_CONNECTION', 'cache'), ], - + ], /* diff --git a/config/responsecache.php b/config/responsecache.php new file mode 100644 index 000000000..52ba56017 --- /dev/null +++ b/config/responsecache.php @@ -0,0 +1,94 @@ + env('RESPONSE_CACHE_ENABLED', true), + + /* + * The given class will determinate if a request should be cached. The + * default class will cache all successful GET-requests. + * + * You can provide your own class given that it implements the + * CacheProfile interface. + */ + 'cache_profile' => Spatie\ResponseCache\CacheProfiles\CacheAllSuccessfulGetRequests::class, + + /* + * Optionally, you can specify a header that will force a cache bypass. + * This can be useful to monitor the performance of your application. + */ + 'cache_bypass_header' => [ + 'name' => env('CACHE_BYPASS_HEADER_NAME', null), + 'value' => env('CACHE_BYPASS_HEADER_VALUE', null), + ], + + /* + * When using the default CacheRequestFilter this setting controls the + * default number of seconds responses must be cached. + */ + 'cache_lifetime_in_seconds' => env('RESPONSE_CACHE_LIFETIME', 60 * 60 * 24 * 7), + + /* + * This setting determines if a http header named with the cache time + * should be added to a cached response. This can be handy when + * debugging. + */ + 'add_cache_time_header' => env('APP_DEBUG', true), + + /* + * This setting determines the name of the http header that contains + * the time at which the response was cached + */ + 'cache_time_header_name' => env('RESPONSE_CACHE_HEADER_NAME', 'laravel-responsecache'), + + /* + * This setting determines if a http header named with the cache age + * should be added to a cached response. This can be handy when + * debugging. + * ONLY works when "add_cache_time_header" is also active! + */ + 'add_cache_age_header' => env('RESPONSE_CACHE_AGE_HEADER', false), + + /* + * This setting determines the name of the http header that contains + * the age of cache + */ + 'cache_age_header_name' => env('RESPONSE_CACHE_AGE_HEADER_NAME', 'laravel-responsecache-age'), + + /* + * Here you may define the cache store that should be used to store + * requests. This can be the name of any store that is + * configured in app/config/cache.php + */ + 'cache_store' => env('RESPONSE_CACHE_DRIVER', 'redis'), + + /* + * Here you may define replacers that dynamically replace content from the response. + * Each replacer must implement the Replacer interface. + */ + 'replacers' => [ + \Spatie\ResponseCache\Replacers\CsrfTokenReplacer::class, + ], + + /* + * If the cache driver you configured supports tags, you may specify a tag name + * here. All responses will be tagged. When clearing the responsecache only + * items with that tag will be flushed. + * + * You may use a string or an array here. + */ + 'cache_tag' => '', + + /* + * This class is responsible for generating a hash for a request. This hash + * is used to look up an cached response. + */ + 'hasher' => \Spatie\ResponseCache\Hasher\DefaultHasher::class, + + /* + * This class is responsible for serializing responses. + */ + 'serializer' => \Spatie\ResponseCache\Serializers\DefaultSerializer::class, +]; diff --git a/packages/Sarga/API/Http/routes.php b/packages/Sarga/API/Http/routes.php index a928a0606..b964c96ad 100644 --- a/packages/Sarga/API/Http/routes.php +++ b/packages/Sarga/API/Http/routes.php @@ -41,7 +41,8 @@ Route::group(['prefix' => 'api'], function () { Route::get('vendor/brands/{vendor_id}',[Vendors::class,'brands'])->name('api.vendor.brands'); //category routes - Route::get('descendant-categories', [Categories::class, 'descendantCategories'])->name('api.descendant-categories'); + Route::get('descendant-categories', [Categories::class, 'descendantCategories'])->middleware('cacheResponse:300') + ->name('api.descendant-categories'); Route::get('categories', [Categories::class, 'allResources'])->name('api.categories'); Route::get('categories/{id}/filters',[Categories::class,'filters']); Route::get('attribute-options', [FilterOptions::class, 'allResources']);