Skip to content

Latest commit

 

History

History
85 lines (59 loc) · 4.18 KB

README.md

File metadata and controls

85 lines (59 loc) · 4.18 KB

logo

project status project stability

Momento Client Libraries for JavaScript

Momento Cache is a fast, simple, pay-as-you-go caching solution without any of the operational overhead required by traditional caching solutions. This repo contains the source code for the Momento client libraries for JavaScript.

To get started with Momento you will need a Momento Auth Token. You can get one from the Momento Console.

Packages

There are two different JavaScript SDKs available for Momento on npmjs. The API is identical in both SDKs, but each is best suited for a particular environment:

  • @gomomento/sdk: the Momento node.js SDK, for use in server-side applications and other node.js environments where performance considerations are key.
  • @gomomento/sdk-web: the Momento web SDK, for use in browsers or other non-node.js JavaScript environments. More portable but less performant for server-side use cases.

Usage

import {CacheClient, CacheGetResponse} from '@gomomento/sdk';

async function main() {
  const cacheClient = await CacheClient.create({
    defaultTtlSeconds: 60,
  });

  await cacheClient.createCache('cache');
  await cacheClient.set('cache', 'foo', 'FOO');
  const getResponse = await cacheClient.get('cache', 'foo');
  if (getResponse.type === CacheGetResponse.Hit) {
    console.log(`Got value: ${getResponse.valueString()}`);
  }
}

main().catch(e => {
  throw e;
});

You'll need a Momento API key to authenticate with Momento. You can get one from the Momento Console.

By default, Momento clients use a CredentialProvider that expects an environment variable named MOMENTO_API_KEY

export MOMENTO_API_KEY=<your Momento API key here>

Note: it is best practice to put the API key into something like AWS Secret Manager or GCP Secret Manager instead of an environment variable for enhanced security. See these docs for more information about instantiating your own CredentialProvider.

Getting Started and Documentation

Documentation is available on the Momento Docs website. For information specific to a particular SDK, see the Node.js SDK documentation or the Web SDK documentation. We also have quickstart guides for both Cache and Topics.

Examples

Working example projects, with all required build configuration files, are available for both the node.js and web SDKs:

Developing

If you are interested in contributing to the SDK, please see the CONTRIBUTING docs.


For more info, visit our website at https://gomomento.com!