Implement Persistence
When deploying an application which uses the Proxy SDK in a highly available manner, the in-memory persistence which the SDK uses by default may not be appropriate, and instead there may be the need to store the transaction information elsewhere.
Some options for this storage would include:
- Some third party data tier such as a RDBMs, noSQL database or Redis
- In an encrypted cookie held and presented by the client
These each have pros and cons and should be selected at the discretion of the application developer.
When a persistence method is decided upon, in order to have the Proxy SDK make use of it is to implement and pass in functions to handle each operation when initializing the SDK :
const config = {
...
};
const transactionFunctions = {
createTransaction: myCreateTransactionFunction,
getTransaction: myGetTransactionFunction,
updateTransaction: myUpdateTransactionFunction,
deleteTransaction: myDeleteTransactionFunction
};
const adaptive = new Adaptive(config, transactionFunctions);
The function prototypes are as follows:
/**
* @property {object} transaction value to store.
* @return {string} the transactionId which the transaction was stored under
*/
function createTransaction(transaction) {}
/**
* @property {string} transactionId ID of transaction to look up
* @return {object} looked up transaction
*/
function getTransaction(transactionId) {}
/**
* @property {string} transactionId index to update
* @property {object} transaction values to update. These values should be added with any existing values in a union where new values take precedence.
*/
function updateTransaction(transactionId, transaction) {}
/**
* @property {string} transactionId to delete
*/
function deleteTransaction(transactionId) {}
Updated over 1 year ago