Managing the Offline Storage

Managing the Offline Storage

Aside from data requests, the Backend Services JavaScript SDK provides operations that you can use to perform maintenance on the app's offline data. These are listed in the sections below:

Purging Offline Data

Sometimes you might need to delete items from the offline storage without synchronizing the delete operation later when the device goes online. To that end, the SDK provides purge operations:

Purging a Content Type

The purge(contentTypeName) method allows you to purge a single content type:

el.offlineStorage.purge(contentTypeName, successFunction, errorFunction);

The method is asynchronous. For information on using it with callbacks or promises, see the API Reference.

Purging All Offline Data

The purgeAll() method allows you to purge the entire content of the offline storage:

el.offlineStorage.purgeAll(successFunction, errorFunction);

The method is asynchronous. For information on using it with callbacks or promises, see the API Reference.

Getting the Unsynchronized Items

The getItemsForSync() method allows you to retrieve from the offline storage all the items that haven't been synchronized.

el.offlineStorage.getItemsForSync();

The response contains full data objects grouped by content type. Each object comes along with an associated user action that tells you what was done with it: create, update, or delete.

For example, the following result shows that a single object in the EmailSubscribers content type has been created:

{
    "EmailSubscribers": [
        {
            "item": {
                "key": "7a50e9c8-ced0-11e4-ba3c-ebac51c2c762",
                "_id": "b1df35b0-02e5-11e5-a0ee-9f0837673bce",
                "CreatedAt": "2015-05-25T13:55:25.963Z",
                "ModifiedAt": "2015-05-25T13:55:25.963Z",
                "CreatedBy": "00000000-0000-0000-0000-000000000000",
                "ModifiedBy": "00000000-0000-0000-0000-000000000000",
                "Owner": "00000000-0000-0000-0000-000000000000"
            },
            "action": "create"
        }
    ]
}

If none of the content types in the offline storage has items to synchronize, the response contains an empty array for each content type:

{
    "EmailSubscribers": [],
    "Activities": []
}

If the offline storage is empty, the response contains an empty object.

The method is asynchronous. For information on using it with callbacks or promises, see the API Reference.

See Also


Start a free trial Request a demo
Contact us: +1-888-365-2779
sales@telerik.com
Copyright © 2016-2017, Progress Software Corporation and/or its subsidiaries or affiliates. All rights reserved.