Ephemeral Exchange is a cross platform cache with a REST API and some useful SDK clients for various platforms. In this example I’ll look at how to use intents to preserve cache atomicity, and the code demo platform will be Apps Script.
Intentions
There are times when you are sharing cache across apps that there may a conflict where two processes try to update the same data item. The full write up on how this works in on github, where you’ll also find the node and JavaScript client. The Apps Script client is here.
The console
You’ll need to register and create a boss key in the API console. That will allow you make access keys for the store.
Generate a boss key
First off we’ll need a writer key. For collaboration purposes you’d probably also create a reader and an updater, but we’ll just stick to a writer for this demo. To create access keys, you need a boss key. You can make one in the API console, or use an existing one, and copy it to use in your script.
Initialize the API
Add the library – it’s reference is
19rhki6VDTWk4v1RDb6u1d5E-nNaQq8sXCnRnFzUpp4V4lmZ9Z6R_PP9n
then
[crayon-627c155d3117d572864810/]
Check service is up if you want
[crayon-627c155d31186129873138/]
Create a writer key
[crayon-627c155d31187263492810/]
Write a data item
[crayon-627c155d31188307154409/]
If you want to read it back normally, with no intention to update
[crayon-627c155d3118a121405951/]
But you can also read it back, with an intention to update it shortly
[crayon-627c155d3118b057537176/]
And it returns an intent key. Now no-one else but this access key and this intent key can update it for a short while
[crayon-627c155d3118c591109918/]
If you to write it you’ll get an error
[crayon-627c155d311aa749313716/]
Here’s what an error looks like
[crayon-627c155d311ab442768537/]
This time it will allow the update since we are passing the intent key as well
[crayon-627c155d311ac812494994/]
If you don’t have an intent key, then it means someone else is working through the process of updating, so you have to wait. When it rejected your request it also told you the time you’d need to wait to be sure the other guy was finished, or his lock expired.
[crayon-627c155d311ad154726230/]
Where to get it
To use the store console, just visit the console and login with your google ID. No other registration is required. See this documentation for how to use the API and Ephemeral Exchange for more info, examples and demos.