Shop It Docs
Developer ResourcesCommunication

Caching in Communication

Redis caching coverage, TTL, cache key scope, and invalidation rules for Communication mobile reads.

Caching in Communication

Audience: Backend developers, frontend developers, QA Scope: Redis-backed caching for Communication mobile read APIs


Overview

Communication now caches the highest-read mobile endpoints in Redis for 30 minutes.

The goals are:

  • reduce repeated DB reads for posts and discussion threads
  • keep user-specific access checks safe
  • invalidate precisely after writes so clients do not read stale content for long

The cache is implemented in:


TTL

SettingValue
Cache TTL30 minutes
TTL in code1800 seconds

Cached Endpoints

EndpointWhat is cachedCache key scopeTTL
GET /api/mobile/channels/:channelId/postsChannel post page responsechannelId + userId + cursor + limit + access-decision fingerprint30 min
GET /api/mobile/posts/:postIdSingle post detailpostId + userId + access-decision fingerprint30 min
GET /api/mobile/channels/:channelId/discussionDiscussion detailchannelId + userId30 min
GET /api/mobile/channels/:channelId/discussion/messagesDiscussion message pagechannelId + userId + beforeSeq + limit + view30 min

Why Post Caches Are Access-Aware

Channel post reads are not globally cacheable because they depend on:

  • current channel access decision
  • read windows from entitlement history
  • post-level visibility filtering

So the post cache key includes an access-decision fingerprint.

That fingerprint is derived from:

  • mode
  • archiveUntil
  • readWindows
  • reasonCode

This prevents one user’s or one access window’s cached result from being reused incorrectly for another decision state.


Invalidation Rules

Cached endpointInvalidated by
GET /api/mobile/channels/:channelId/postsPost create, update, pin/unpin, soft delete, restore, replace post visibility rules
GET /api/mobile/posts/:postIdPost create, update, pin/unpin, soft delete, restore, replace post visibility rules
GET /api/mobile/channels/:channelId/discussionDiscussion create, discussion update, discussion message create/update/delete/restore, slow mode update
GET /api/mobile/channels/:channelId/discussion/messagesDiscussion message create/update/delete/restore, discussion create/update, slow mode update

Invalidation Source Files

Post Cache Invalidation

Discussion Cache Invalidation


Read-Path Integration

These mobile read services now use Redis cache reads:

The shared provider is exported from:


Staleness Strategy

Communication does not rely only on TTL expiry.

Instead:

  • reads are cached for up to 30 minutes
  • writes actively invalidate the affected read-model caches
  • TTL acts as a fallback safety net, not the only freshness mechanism

This keeps the system:

  • fast for repeated reads
  • safe after writes
  • easier to reason about during QA

Important Notes

  • Channel list and channel detail are not part of this cache layer yet.
  • Post caches are user-scoped and access-aware.
  • Discussion caches are user-scoped.
  • Invalidation uses pattern-based clearing for the affected post or channel scope.

Summary

Communication caching currently targets:

  • channel post list
  • post detail
  • discussion detail
  • discussion message list

with:

  • 30 minute TTL
  • user-scoped cache keys
  • access-aware post cache keys
  • write-time invalidation to minimize stale reads