Deprecated
NOTE – as of 20 Nov 2017, Ephemeral exchange is migrating to a Firestore/ Firebase cloud function back end. See Migrating from App Engine to Cloud function

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-616f1e75195bd558875135/]

 Check service is up if you want

[crayon-616f1e75195c6950980700/]

Create a writer key

[crayon-616f1e75195c7257572738/]

Write a data item

[crayon-616f1e75195c9484792907/]

If you want to read it back normally, with no intention to update

[crayon-616f1e75195d7177001102/]

But you can also read it back, with an intention to update it shortly

[crayon-616f1e75195d8476759531/]

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-616f1e75195d9378932268/]

If you to write it you’ll get an error

[crayon-616f1e75195e2024741236/]

Here’s what an error looks like

[crayon-616f1e75195e4948134663/]

This time it will allow the update since we are passing the intent key as well

[crayon-616f1e75195e5945577795/]

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-616f1e75195e6082052404/]

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.