Winows Azure Cache client and Express session store
The azurecache module allows you to use the Windows Azure Cache Service to store session state in Express applications. It also allows direct access to Windows Azure Cache Service from other Node.js applications.
The azurecache module uses Edge.js and as such it currently only works on Windows. It is a great fit for storing session state of Express applications hosted in Windows Azure Web Sites. It is also a good choice for any other type of Node.js application hosted in Windows Azure that requires caching.
First create your Windows Azure Cache Service instance following insturctions at Scott Guthrie's blog. You will end up with an endpoint URL of your cache service (e.g. tjanczuk.cache.windows.net) and an access key (a long Base64 encoded string).
Then install the azurecache and express modules:
npm install azurecachenpm install express
Next author your Express application that uses the azurecache module to store Express session state in the Windows Azure Cache Service:
var express =AzureCacheStore = express;var app = ;app;app;app;app;app;
Lastly set some environment variables and start your server:
set AZURE_CACHE_IDENTIFIER=<your_azure_cache_endpoint_url>set AZURE_CACHE_TOKEN=<your_azure_cache_access_key>node server.js
Every time you visit http://localhost:3000/inc in the browser you will receive an ever increasing counter value. When you visit http://localhost:3000/get you will receive the current counter value. The value of the counter is stored as part of the Express session state in the Windows Azure Cache Service with a default TTL of one day.
You can specify the credentials to the Windows Azure Cache Service either in code or via environment variables:
var azureCacheOptions =identifier: '<your_endpoint_url>' // or set the AZURE_CACHE_IDENTIFIER environment variabletoken: '<your_access_key>' // or set the AZURE_CACHE_TOKEN environment variablettl: 3600 // optional TTL in seconds (default 1 day); or set the AZURE_CACHE_TTL env variable;// ...app;
You can access Windows Azure Cache Service directly too:
var azurecache =var cache = azurecache;cache;
I do take contributions. Feedback welcome (file an issue). Enjoy!