feat: Обновить логику кэширования для запросов GET, добавив исключение для /communities, чтобы всегда запрашивать свежие данные и улучшить обработку заголовков If-None-Match
Publish Fast Tabler Docker image / build-and-push-fast (push) Successful in 1m56s
Publish Fast Tabler Docker image / build-and-push-fast (push) Successful in 1m56s
This commit is contained in:
+15
-5
@@ -87,11 +87,21 @@ api.interceptors.request.use((config) => {
|
||||
// If-None-Match для GET на базе кеша
|
||||
const method = String(config.method || 'get').toLowerCase();
|
||||
if (method === 'get') {
|
||||
const key = buildCacheKey(config);
|
||||
const cached = responseCache.get(key);
|
||||
if (cached?.etag) {
|
||||
config.headers = config.headers || {};
|
||||
if (!config.headers['If-None-Match']) config.headers['If-None-Match'] = String(cached.etag);
|
||||
// Исключение: для /communities всегда запрашиваем свежие данные (без условного GET)
|
||||
const rawUrl = String(config.url || '');
|
||||
const pathOnly = rawUrl.split('?')[0];
|
||||
const isCommunities = pathOnly === '/communities' || pathOnly.endsWith('/communities');
|
||||
|
||||
if (!isCommunities) {
|
||||
const key = buildCacheKey(config);
|
||||
const cached = responseCache.get(key);
|
||||
if (cached?.etag) {
|
||||
config.headers = config.headers || {};
|
||||
if (!config.headers['If-None-Match']) config.headers['If-None-Match'] = String(cached.etag);
|
||||
}
|
||||
} else if (config.headers && config.headers['If-None-Match']) {
|
||||
// На всякий случай удалим, если был выставлен где-то ещё
|
||||
delete config.headers['If-None-Match'];
|
||||
}
|
||||
}
|
||||
// Если заголовок не указан, но в теле есть etag — пробуем проставить If-Match
|
||||
|
||||
Reference in New Issue
Block a user