Skip to main content
With offline support enabled, every list and lookup the SDK already offers answers from the on-device cache first and then from the server. Your UI paints instantly from the cache, then reconciles when the server replies. This page describes that contract, the reads it applies to, and how to merge the two phases.

The two-phase contract

Each read fires up to two callbacks, always in this order:
1

Cached phase

The SDK delivers a page from the local cache first, synchronously-fast. It fires even when the page is empty — an empty cached page is indistinguishable from a cache miss, by design. Render it right away.
2

Server phase

After a successful server response, the SDK delivers the server’s copy for the same slice and writes it through to the cache before the callback. Reconcile your displayed list against it. (Blocked users are the exception: their server page is delivered but not written to the cache, which keeps that list current through its own background refresh.)
Two rules follow from this:
  • Offline, the read ends with an error. After the cached page, a read that gets no answer because the device is offline settles with onError, code ERROR_INTERNET_UNAVAILABLE. A real server error reaches onError unchanged. The call always settles, as long as you wait for each fetch to return before starting the next one on the same request object.
  • The server phase never fires offline. It fires only on a genuine server response. Never treat a cached page as “end of history”; an empty cached page only means the end of the cached window.
With offline support off, these new listeners behave like the classic callback: the cached phase never fires, and the server result arrives in onServer… instead of onSuccess. Nothing changes until you call enabled(true) (see Enable Offline Support). Minimum version 5.1.0.

Read messages

MessagesRequest supports both directions. fetchPrevious pages toward older messages; fetchNext pages toward newer ones. Both take a MessageFetchListener.
Starting with v5.1.0, the CallbackListener overload of `fetchPrevious()` / `fetchNext()` is deprecated. Use `MessageFetchListener` instead; it requires SDK 5.1.0 or later, so on 5.0.x keep using CallbackListener. With offline support off, it behaves exactly like the old callback: onError is unchanged, and the server result arrives in the onServer… callback instead of onSuccess. With offline support on, it also delivers the cached result first; the old overload keeps working but receives only the server result. See Show Cached Data.

Read conversations

ConversationsRequest pages in one direction with fetchNext, taking a ConversationFetchListener.
Starting with v5.1.0, the CallbackListener overload of `fetchNext()` is deprecated. Use `ConversationFetchListener` instead; it requires SDK 5.1.0 or later, so on 5.0.x keep using CallbackListener. With offline support off, it behaves exactly like the old callback: onError is unchanged, and the server result arrives in the onServer… callback instead of onSuccess. With offline support on, it also delivers the cached result first; the old overload keeps working but receives only the server result. See Show Cached Data.

Read the other lists

Every remaining list read gains the same two-phase overload. Each has its own listener with cached/server callbacks of the matching type plus onError. The call shape is identical to the conversations example above — swap the request, the listener, and the callback names.
For ReactionsRequest, use one request object per direction: an object caches only the first direction it fetches, and its cached phase stays empty in the other direction. Users, groups, members, banned members, reactions, and the notification feed are served from a per-request snapshot rather than a shared store; per-builder details live in the Offline Behaviour table on each request’s own page — Retrieve Users, Retrieve Groups, Retrieve Group Members, Block Users, and Reactions.

Read a single item

getConversation and getMessageDetails each add a two-phase overload. Unlike the list reads, the cached callback fires only when the item is cached — never with an empty or null object. A cache miss goes straight to the server phase online, or straight to onError offline.
Starting with v5.1.0, the CallbackListener overload of `getConversation()` is deprecated. Use `ConversationDetailsListener` instead; it requires SDK 5.1.0 or later, so on 5.0.x keep using CallbackListener. With offline support off, it behaves exactly like the old callback: onError is unchanged, and the server result arrives in the onServer… callback instead of onSuccess. With offline support on, it also delivers the cached result first; the old overload keeps working but receives only the server result. See Show Cached Data.

Merge the two phases

The server phase replaces the same slice — it is a reconcile, not a second batch. Render the cached page straight away, then on the server phase diff it into your displayed list keyed by the item’s stable id (message id, conversation id, uid, guid). Do not append the server page to the cached one.
Key your list by id so the two phases merge cleanly: update items that changed, add new ones, and drop cached items the server slice omits. To page further back, issue the next fetchPrevious() / fetchNext() rather than treating the server phase as more pages.

When the cached page is empty

The cache answers a read only if every filter on it is locally computable. A single server-only predicate makes the entire cached phase return an empty list — with no error and no warning — while the server phase still answers in full. The guiding rule is better empty than wrong. The most common server-only predicate is searchKeyword, which blanks the cached phase on any request that carries a search keyword (threads, reactions and the notification feed never carry one). Other examples include hasLinks, updatesOnly, and setInteractionGoalCompletedOnly on MessagesRequest, setting a UID and a GUID together outside a thread (one sender’s messages in a group), and the presence filters (UsersRequest.setUserStatus, GroupMembersRequest.setStatus) on the entity lists.
An offline-critical screen must use only cache-supported filters — one innocuous builder flag can silently disable the cached phase for a whole screen. Each request’s own page carries an Offline Behaviour table of exactly what its cache answers — Conversations, Message filters, Users, Groups, Group Members, Kick / Ban, Block Users, Threads, Mentions, Reactions, and Campaigns.