Write locks
Write locks ensure that when you update a data item, you can't overwrite changes from somewhere else. For example, if there are changes in a different part of your code, or from a Cloud Code script.
For an example of how to use a write lock, refer to the SaveItem
class in the Cloud Save SDK.
Enforces conflict checks
Read and write commands both return a writeLock
, which you can store locally. When you save a value, you can include the writeLock
that you obtained. If the write lock doesn't match what's in the Cloud Save service, the service returns an error to indicate that the value in the service has been updated since the last time you retrieved the write lock.
Conflict resolution
If you encounter a write lock error, you can proceed with one of the following:
- If you're certain the value you want to save is correct, you can bypass the write lock to overwrite any changes.
- To update the value and write lock from the Cloud Save service, read the value again. You can then manually resolve the conflict.
Write lock omission
Item creation
To avoid unnecessary errors, you need to omit the writeLock
field when you create a new data item.
Overwrite changes
To skip write lock validation, you can set the writeLock
field for an item to null
. A null write lock means that you overwrite any existing value stored for that item.