-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
when product save and need delete the all images for it
- Loading branch information
Showing
2 changed files
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
namespace NexaMerchant\Apis\Http\Middleware; | ||
|
||
use Closure; | ||
use Illuminate\Support\Facades\Cache; | ||
use Illuminate\Support\Facades\Log; | ||
use Illuminate\Support\Str; | ||
|
||
class AdminCacheResponse | ||
{ | ||
/** | ||
* Handle an incoming request. | ||
* | ||
* @param \Illuminate\Http\Request $request | ||
* @param \Closure $next | ||
* @return mixed | ||
*/ | ||
public function handle($request, Closure $next) | ||
{ | ||
// url the url path and query string as cache key, need sort query string | ||
// when query string include clean-cache, and it's value is true, then clean cache | ||
|
||
$cacheKey = $this->makePageCacheKey($request->fullUrl()); | ||
|
||
$cacheKey = 'api_cache_' . $cacheKey; | ||
|
||
if (Cache::has($cacheKey)) { | ||
$cacheData = Cache::get($cacheKey); | ||
$cacheData = json_decode($cacheData, true); | ||
return response()->json($cacheData); | ||
} | ||
|
||
$response = $next($request); | ||
|
||
Cache::put($cacheKey, $response->getContent(), 3600); // Cache for | ||
|
||
return $response; | ||
} | ||
|
||
private function makePageCacheKey($url){ | ||
return 'api_cache_' . Str::slug($url); | ||
} | ||
} |