Momento Client Library for Dart
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 library for Dart.
To get started with Momento you will need a Momento Auth Token. You can get one from the Momento Console.
- Website: https://www.gomomento.com/
- Momento Documentation: https://docs.momentohq.com/
- Getting Started: https://docs.momentohq.com/getting-started
- Momento SDK Documentation for Dart: https://docs.momentohq.com/sdks/dart
- Discuss: Momento Discord
Momento Dart SDK
To get started with Momento you will need a Momento API key. You can get one from the Momento Console.
- Website: https://www.gomomento.com/
- Momento Documentation: https://docs.momentohq.com/
- Getting Started: https://docs.momentohq.com/getting-started
- Discuss: Momento Discord
Packages
The Momento Dart SDK is available on pub.dev
To install in your Dart program, use:
dart pub add momento
To install in your Flutter program, use:
flutter pub add momento
Usage
Check out our example directory for complete examples of using the Momento Dart SDK to implement a publish and subscribe system in a basic Dart program and in a Flutter app.
Here is a quickstart you can use for your own project:
import 'package:momento/momento.dart';
Future<void> main() async {
final cacheClient = CacheClient(
CredentialProvider.fromEnvironmentVariable("MOMENTO_API_KEY"),
CacheClientConfigurations.latest(),
Duration(seconds: 30));
final cacheName = "cache";
final key = "key";
final value = "value";
final createResp = await cacheClient.createCache(cacheName);
switch (createResp) {
case CreateCacheSuccess():
print("Cache created!");
case CreateCacheAlreadyExists():
print("Cache already exists!");
case CreateCacheError():
print(
"Cache creation error: ${createResp.errorCode} ${createResp.message}");
}
final setResp = await cacheClient.set(cacheName, key, value);
switch (setResp) {
case SetSuccess():
print("Set successful!");
case SetError():
print("Set error: ${setResp.errorCode} ${setResp.message}");
}
final getResp = await cacheClient.get(cacheName, key);
switch (getResp) {
case GetHit():
print("Found value in $cacheName: ${getResp.value}");
case GetMiss():
print("Value was not found in $cacheName!");
case GetError():
print("Got an error: ${getResp.errorCode} ${getResp.message}");
}
await cacheClient.close();
}
Getting Started and Documentation
General documentation on Momento and the Momento SDKs is available on the Momento Docs website. Specific usage examples for the Dart SDK are coming soon!
Examples
Check out full working code in the example directory of this repository!
Logging
There is a LogLevel
enum that contains the following log levels:
LogLevel.trace
LogLevel.debug
LogLevel.info
LogLevel.warn
LogLevel.error
LogLevel.fatal
LogLevel.off
This enum can be used to configure the logging level of the Momento package. By default, the logging level is set to LogLevel.info
. To change the logging level, pass the desired level to the Configuration
constructor:
var config = Mobile.latest(logLevel: LogLevel.debug);
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!
Libraries
- generated/auth.pb
- generated/auth.pbenum
- generated/auth.pbgrpc
- generated/auth.pbjson
- generated/cacheclient.pb
- generated/cacheclient.pbenum
- generated/cacheclient.pbgrpc
- generated/cacheclient.pbjson
- generated/cacheping.pb
- generated/cacheping.pbenum
- generated/cacheping.pbgrpc
- generated/cacheping.pbjson
- generated/cachepubsub.pb
- generated/cachepubsub.pbenum
- generated/cachepubsub.pbgrpc
- generated/cachepubsub.pbjson
- generated/controlclient.pb
- generated/controlclient.pbenum
- generated/controlclient.pbgrpc
- generated/controlclient.pbjson
- generated/leaderboard.pb
- generated/leaderboard.pbenum
- generated/leaderboard.pbgrpc
- generated/leaderboard.pbjson
- generated/permissionmessages.pb
- generated/permissionmessages.pbenum
- generated/permissionmessages.pbjson
- generated/token.pb
- generated/token.pbenum
- generated/token.pbgrpc
- generated/token.pbjson
- generated/vectorindex.pb
- generated/vectorindex.pbenum
- generated/vectorindex.pbgrpc
- generated/vectorindex.pbjson
- generated/webhook.pb
- generated/webhook.pbenum
- generated/webhook.pbgrpc
- generated/webhook.pbjson
- momento
- Support for doing something awesome.