Skip to content

[Perf] Replace hardcoded cache TTLs with a dynamic tier-based strategy #648

Description

@nanaf6203-bit

Problem Statement

src/lib/cacheManager.ts and src/lib/redisCache.ts hardcode TTLs:

PROPERTY_LISTINGS: 5 * 60,
PROPERTY_DETAILS: 1 * 60,
SEARCH_RESULTS: 5 * 60,
AUTOCOMPLETE: 10 * 60

There is no environment-aware tuning. In dev/staging, indexes shift frequently; in production, longer TTLs are safe but invalidate stale snapshots faster than necessary. There's no per-tenant TTL override.

Expected Outcome

  • TTLs are computed dynamically based on NODE_ENV, feature flag, or per-property hotness
  • A function ttlFor(contentType, hotnessTier) returns the right seconds
  • A future per-region override is one place to plug in

Acceptance Criteria

  • New src/lib/cacheTtl.ts module with documented tier mappings
  • Old hardcoded constants removed from callers
  • Tests verify TTL under each tier

Implementation Notes

Introduce hotness = (recentAccesses) => high | medium | low and look up from a tier table. Default tier: medium.

Files Likely Affected

  • src/lib/redisCache.ts
  • src/lib/cacheManager.ts
  • Possibly: src/lib/propertyService.ts (consumers)

Difficulty / Effort

  • Difficulty: Easy
  • Effort: T-Shirt S

Labels

enhancement, priority:medium, area:performance, area:caching

Metadata

Metadata

Assignees

Labels

Stellar WaveIssues in the Stellar wave program

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions