Skip to content

Commit f880712

Browse files
committed
Fix: Critical cache key collision bug - include all query parameters in cache key
Previously, generateQueryCacheKey() only included a hardcoded whitelist of 11 parameters, causing cache key collisions when different filter values were used (e.g., type=customer vs type=contact generated the same cache key). This fix includes ALL query parameters in the cache key generation, excluding only internal/cache-busting parameters like '_', 'timestamp', 'nocache', and '_method'. Impact: - Fixes data integrity issue where different queries returned cached results from other queries - Ensures accurate cache HIT/MISS behavior for all filter combinations - Backward compatible - existing cache keys will naturally expire and regenerate Example: Before: /contacts?type=customer and /contacts?type=contact had SAME cache key After: /contacts?type=customer and /contacts?type=contact have DIFFERENT cache keys
1 parent 20c66f2 commit f880712

1 file changed

Lines changed: 14 additions & 13 deletions

File tree

src/Support/ApiModelCache.php

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -58,21 +58,22 @@ public static function generateQueryCacheKey(Model $model, Request $request, arr
5858
$table = $model->getTable();
5959
$companyUuid = static::getCompanyUuid($request);
6060

61-
// Get all relevant query parameters
62-
$params = [
63-
'limit' => $request->input('limit'),
64-
'offset' => $request->input('offset'),
65-
'page' => $request->input('page'),
66-
'sort' => $request->input('sort'),
67-
'order' => $request->input('order'),
68-
'query' => $request->input('query'),
69-
'search' => $request->input('search'),
70-
'filter' => $request->input('filter'),
71-
'with' => $request->input('with'),
72-
'expand' => $request->input('expand'),
73-
'columns' => $request->input('columns'),
61+
// Get ALL query parameters from the request
62+
// This ensures different filters (e.g., type=customer vs type=contact) generate different cache keys
63+
$params = $request->query();
64+
65+
// Remove internal/non-cacheable parameters that shouldn't affect cache key
66+
$excludedParams = [
67+
'_', // Cache-busting timestamp
68+
'timestamp', // Cache-busting timestamp
69+
'nocache', // Explicit cache bypass
70+
'_method', // Laravel method override
7471
];
7572

73+
foreach ($excludedParams as $excluded) {
74+
unset($params[$excluded]);
75+
}
76+
7677
// Merge additional parameters
7778
$params = array_merge($params, $additionalParams);
7879

0 commit comments

Comments
 (0)