momento 0.2.0 momento: ^0.2.0 copied to clipboard
Dart client for interacting with Momento
Momento Dart Client Library #
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 Dart client library.
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
- Dart SDK Documentation: 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!