Skip to content

Commit

Permalink
feat: add CacheClient close method (#80)
Browse files Browse the repository at this point in the history
* feat: add CacheClient close method

* remove unused imports from examples
  • Loading branch information
anitarua committed Jan 8, 2024
1 parent 6de1b98 commit 411d432
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 7 deletions.
5 changes: 2 additions & 3 deletions example/quickstart/quickstart.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'dart:io';
import 'package:momento/momento.dart';

void main() async {
Future<void> main() async {
final cacheClient = CacheClient(
CredentialProvider.fromEnvironmentVariable("MOMENTO_API_KEY"),
MobileCacheConfiguration.latest(),
Expand Down Expand Up @@ -29,5 +28,5 @@ void main() async {
print("Got an error: ${getResp.errorCode} ${getResp.message}");
}

exit(0);
await cacheClient.close();
}
1 change: 0 additions & 1 deletion example/topics/advanced.dart
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,4 @@ void main() async {

topicClient.close();
print("End of Momento topics example");
exit(0);
}
1 change: 0 additions & 1 deletion example/topics/basic_publisher.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,4 @@ void main() async {

topicClient.close();
print("Closed Momento Topics publisher");
exit(0);
}
2 changes: 0 additions & 2 deletions example/topics/basic_subscriber.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'dart:async';
import 'dart:io';
import 'package:momento/momento.dart';

void main() async {
Expand Down Expand Up @@ -38,5 +37,4 @@ void main() async {

topicClient.close();
print("Closed Momento Topics subscriber");
exit(0);
}
8 changes: 8 additions & 0 deletions lib/src/cache_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ abstract class ICacheClient {
{Duration? ttl});

Future<DeleteResponse> delete(String cacheName, Value key);

Future<void> close();
}

class CacheClient implements ICacheClient {
Expand Down Expand Up @@ -117,4 +119,10 @@ class CacheClient implements ICacheClient {
}
return _dataClient.delete(cacheName, key);
}

@override
Future<void> close() async {
await _dataClient.close();
await _controlClient.close();
}
}
7 changes: 7 additions & 0 deletions lib/src/internal/control_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ abstract class AbstractControlClient {
Future<DeleteCacheResponse> deleteCache(String cacheName);

Future<ListCachesResponse> listCaches();

Future<void> close();
}

class ControlClient implements AbstractControlClient {
Expand Down Expand Up @@ -83,4 +85,9 @@ class ControlClient implements AbstractControlClient {
}
}
}

@override
Future<void> close() async {
await _channel.shutdown();
}
}
7 changes: 7 additions & 0 deletions lib/src/internal/data_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ abstract class AbstractDataClient {
{Duration? ttl});

Future<DeleteResponse> delete(String cacheName, Value key);

Future<void> close();
}

class DataClient implements AbstractDataClient {
Expand Down Expand Up @@ -100,4 +102,9 @@ class DataClient implements AbstractDataClient {
}
}
}

@override
Future<void> close() async {
await _channel.shutdown();
}
}

0 comments on commit 411d432

Please sign in to comment.