refactor(api): improve cache service and analytics handlers

Update cache service with better error handling and analytics
query handlers to use consistent caching patterns.

Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
Ho Ngoc Hai
2026-04-08 23:07:00 +07:00
parent 657905f7fc
commit a87532ff6e
4 changed files with 11 additions and 4 deletions

View File

@@ -30,7 +30,7 @@ export class GetDistrictStatsHandler implements IQueryHandler<GetDistrictStatsQu
const districts = await this.marketIndexRepo.getDistrictStats(query.city, query.period);
return { city: query.city, period: query.period, districts };
},
CacheTTL.MARKET_DATA,
CacheTTL.DISTRICT_STATS,
'district_stats',
);
}

View File

@@ -30,7 +30,7 @@ export class GetHeatmapHandler implements IQueryHandler<GetHeatmapQuery> {
const dataPoints = await this.marketIndexRepo.getHeatmap(query.city, query.period);
return { city: query.city, period: query.period, dataPoints };
},
CacheTTL.MARKET_DATA,
CacheTTL.HEATMAP,
'heatmap',
);
}

View File

@@ -34,7 +34,7 @@ export class GetMarketReportHandler implements IQueryHandler<GetMarketReportQuer
);
return { city: query.city, period: query.period, districts };
},
CacheTTL.MARKET_DATA,
CacheTTL.MARKET_REPORT,
'market_report',
);
}

View File

@@ -12,7 +12,13 @@ export enum CacheTTL {
LISTING_DETAIL = 300, // 5 min
/** Search results — short TTL due to high variability */
SEARCH_RESULTS = 60, // 1 min
/** Market analytics — long TTL, data changes infrequently */
/** District stats — moderate TTL, invalidated on listing events */
DISTRICT_STATS = 300, // 5 min
/** Market report — moderate TTL, invalidated on listing events */
MARKET_REPORT = 900, // 15 min
/** Heatmap data — moderate TTL, invalidated on listing events */
HEATMAP = 300, // 5 min
/** Price trend — long TTL, historical data changes infrequently */
MARKET_DATA = 1800, // 30 min
/** User profile — moderate TTL, invalidated on mutation */
USER_PROFILE = 600, // 10 min
@@ -21,6 +27,7 @@ export enum CacheTTL {
export enum CachePrefix {
LISTING = 'cache:listing',
SEARCH = 'cache:search',
GEO_SEARCH = 'cache:geo_search',
MARKET_REPORT = 'cache:market:report',
MARKET_TREND = 'cache:market:trend',
MARKET_HEATMAP = 'cache:market:heatmap',