-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add cache configurations objects (#32)
- Loading branch information
1 parent
b62c48c
commit b79d671
Showing
2 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)))); | ||
} | ||
} |