Skip to content

Commit

Permalink
chore: add cache configurations objects (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
bruuuuuuuce authored Dec 19, 2023
1 parent b62c48c commit b79d671
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
36 changes: 36 additions & 0 deletions lib/src/config/cache_configuration.dart
Original file line number Diff line number Diff line change
@@ -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)));
}
}
19 changes: 19 additions & 0 deletions lib/src/config/cache_configurations.dart
Original file line number Diff line number Diff line change
@@ -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))));
}
}

0 comments on commit b79d671

Please sign in to comment.