Local caching
Local caching is a better option than SyncManager for iOS for rapid access to the data from the local cache and Sendbird server. If you are currently using SyncManager, we strongly encourage you to migrate to the Chat SDK with local caching for enhanced usability and easier maintenance.
Note: SyncManager will be deprecated soon.
The following table displays the full range of differences between local caching and SyncManager.
Local caching | SyncManager | |
---|---|---|
Implementation | Integrated to Chat SDK | Add-on to Chat SDK |
Architecture | View-driven | Event-driven |
Synchronization | ||
Supported | Not supported |
One distinct advantage of local caching over SyncManager is that it provides an event context
and a callback for identifying what changes are made to which group channels and messages. This facilitates locating and debugging issues in those channels.
SyncManager relies on an event-driven architecture where its collection handlers receive all events that pass through the WebSocket connection along with the data in the local cache. In contrast, local caching relies on a view-driven structure where only those events that directly affect the user’s channel list and chat view are delivered to their respective collections.
Another advantage of local caching is that messages that were not sent the first time are automatically resent at a later time. When the WebSocket connection is lost, messages considered “pending” are stored locally until the connection comes back on, at which point the pending messages are automatically sent. This new functionality unique to local caching is called auto resend.
Note: SyncManager will continue to work if the dependency to SyncManager is not removed. The dependency should be deleted once the migration to local caching is completed.
Initialization
You can initialize the Chat SDK with or without local caching. The useCaching
is the boolean that determines if you are going to be using local caching. By default, the Chat SDK is initialized without local caching, the useCaching
set to false. If the useCaching
is set to true, the Chat SDK is initialized with local caching.
In local caching, the completionHandler:
callbacks are added to the initWithApplicationId
method, which receives the initialization status through different event handlers. For Objective-C, the migrationStartHandler:
is called when there's a change in the local cache. Meanwhile, the completionHandler:
lets the client app know whether the Chat SDK has been successfully initialized.
Note: If initialization fails to complete while the
useCaching
is set to true, Chat SDK will operate as if theuseCaching
is set to false.
Connect to Sendbird server
Local caching and SyncManager are alike in keeping chat in the client app up-to-date even when the app is not connected to Sendbird server. The key difference between SyncManager and local caching at the initialization stage is that local caching requires calling the SBDMain.connect()
after the initWithApplicationId
. Calling the SBDMain.connect()
after the initWithApplicationId
is optional when using SyncManager because the SBSMSyncManager.setup
is called immediately after the initWithApplicationId
during the initialization process. Calling the SBDMain.connect()
after the initWithApplicationId
is required when using local caching because some platforms receive the result of initWithApplicationId
as a callback.
Swift
Objective-C
Other methods
Below you will find the new cache-related interfaces that come with local caching. Local caching’s SBDMain.clearCachedData()
replaces the functionality of SyncManager’s SBSMSyncManager.clearCache()
, which deletes the entire data file. In addition, the SBDMain.clearCachedMessages()
and the SBDMain.getCachedDataSize()
are available in local caching. The following table displays a full description of each method and if the method should be called before or after the initWithApplicationId
.
Method | Description |
---|---|
| - Deletes the entire data file. |
| - Clears cached messages in a specific channel. |
| - Checks for the current cached data size. |