Cache Channels
Cache channels remember the latest server-triggered event and send it to new subscribers before future live events.
Use cache channels for "current state" surfaces such as locations, prices, counters, dashboards, and document metadata.
#Channel names
| Channel behavior | Prefix |
|---|---|
| Public cache | cache- |
| Private cache | private-cache- |
| Presence cache | presence-cache- |
| Encrypted cache | private-encrypted-cache- |
#Subscribe
const channel = pusher.subscribe('cache-location.42');
channel.bind('location.updated', (event) => {
console.log(event);
});
channel.bind('pusher:cache_miss', () => {
console.log('No cached event exists yet.');
});Private, presence, and encrypted cache channels use the same auth flow as their non-cache equivalents.
#Populating the cache
Only server-triggered events populate cache channels.
POST https://api.vask.dev/apps/{app_key}/events{
"name": "location.updated",
"channel": "cache-location.42",
"data": "{\"lat\":51.5,\"lng\":-0.12}"
}The next subscriber to cache-location.42 receives that event after subscription succeeds.
#Cache miss handling
When a cache channel has no cached value, Vask can notify both client and server:
- Client:
pusher:cache_miss - Webhook:
cache_miss
The usual pattern is:
- Client subscribes to a cache channel.
- Vask has no cached event.
- Your backend receives a
cache_misswebhook or your client reacts topusher:cache_miss. - Your backend triggers a fresh event to the cache channel.
#Querying cache state
Use the HTTP API with info=cache.
GET https://api.vask.dev/apps/{app_key}/channels/cache-location.42?info=cache{
"occupied": true,
"cache": {
"event": "location.updated",
"data": "{\"lat\":51.5,\"lng\":-0.12}",
"ttl": 60
}
}Prefer raw markdown? View this page as markdown.