Implement real-time presence tracking with PubNub
79
Quality
67%
Does it follow best practices?
Impact
98%
1.07xAverage score across 5 eval scenarios
{
"context": "An application with many chat rooms needs to display occupancy counts on a room listing page. Fetching live occupancy from PubNub for every room on every render would be expensive and slow. A caching layer is needed to reduce API calls while keeping data reasonably fresh.",
"type": "weighted_checklist",
"checklist": [
{
"name": "Map-based cache",
"description": "Uses a Map (or equivalent) keyed by channel name to store cached presence data",
"max_score": 15
},
{
"name": "TTL-based expiry",
"description": "Each cache entry stores a timestamp and the cache checks if the entry has expired based on a configurable TTL (time-to-live) value, defaulting to approximately 30 seconds",
"max_score": 25
},
{
"name": "Returns cached on hit",
"description": "When a cache entry exists and has not expired, the cached value is returned without making an API call to PubNub",
"max_score": 20
},
{
"name": "Fetches on miss or expiry",
"description": "When no cache entry exists or the entry has expired, a fresh hereNow() call is made and the result is stored in the cache",
"max_score": 15
},
{
"name": "Optimized hereNow flags",
"description": "When only the occupancy count is needed, the hereNow() call sets includeUUIDs to false and includeState to false to reduce payload size",
"max_score": 15
},
{
"name": "Multi-channel support",
"description": "The cache supports fetching and caching presence data for multiple channels, either individually or via a batch hereNow call with an array of channels",
"max_score": 10
}
]
}