diff --git a/lib/src/config/cache_configuration.dart b/lib/src/config/cache_configuration.dart new file mode 100644 index 0000000..912dd67 --- /dev/null +++ b/lib/src/config/cache_configuration.dart @@ -0,0 +1,36 @@ +import 'package:client_sdk_dart/src/config/transport/grpc_configuration.dart'; +import 'package:client_sdk_dart/src/config/transport/transport_strategy.dart'; + +abstract interface class CacheConfiguration { + /// Configures low-level options for network interactions with the Momento service + late TransportStrategy transportStrategy; + + /// Constructor for a CacheConfiguration + CacheConfiguration(this.transportStrategy); + + /// Copy constructor for overriding TransportStrategy + CacheConfiguration withTransportStrategy(TransportStrategy transportStrategy); + + /// Convenience copy constructor that updates the client-side + /// timeout setting in the transport strategy + CacheConfiguration withDeadline(Duration deadline); +} + +class CacheClientConfiguration implements CacheConfiguration { + @override + late TransportStrategy transportStrategy; + + CacheClientConfiguration(this.transportStrategy); + + @override + CacheConfiguration withTransportStrategy( + TransportStrategy transportStrategy) { + return CacheClientConfiguration(transportStrategy); + } + + @override + CacheConfiguration withDeadline(Duration deadline) { + return CacheClientConfiguration( + StaticTransportStrategy(StaticGrpcConfiguration(deadline))); + } +} diff --git a/lib/src/config/cache_configurations.dart b/lib/src/config/cache_configurations.dart new file mode 100644 index 0000000..38d868b --- /dev/null +++ b/lib/src/config/cache_configurations.dart @@ -0,0 +1,19 @@ +import 'package:client_sdk_dart/src/config/transport/grpc_configuration.dart'; +import 'package:client_sdk_dart/src/config/transport/transport_strategy.dart'; + +import 'cache_configuration.dart'; + +/// Prebuilt configurations for Momento Cache clients +abstract interface class CacheClientConfigurations {} + +/// Provides prebuilt configurations for the `CacheClient` on mobile platforms +class Mobile extends CacheClientConfigurations { + static CacheClientConfiguration defaultConfig() { + return latest(); + } + + static CacheClientConfiguration latest() { + return CacheClientConfiguration(StaticTransportStrategy( + StaticGrpcConfiguration(Duration(seconds: 15)))); + } +}