Skip to content

pgautier404/client-sdk-javascript

 
 

Repository files navigation

logo

project status project stability

Momento JavaScript Client Libraries

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 JavaScript client libraries.

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 {CacheGet, CacheClient, Configurations, CredentialProvider} from '@gomomento/sdk';

async function main() {
  const cacheClient = new CacheClient({
    configuration: Configurations.Laptop.v1(),
    credentialProvider: CredentialProvider.fromEnvironmentVariable({
      environmentVariableName: 'MOMENTO_AUTH_TOKEN',
    }),
    defaultTtlSeconds: 60,
  });

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

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

Getting Started and Documentation

Documentation is available on the Momento Docs website.

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!

About

Official JavaScript SDK for Momento Serverless Cache

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 99.2%
  • Other 0.8%