29 lines
583 B
Dart
29 lines
583 B
Dart
|
|
typedef CacheScopeProvider = String? Function();
|
||
|
|
|
||
|
|
class CacheScope {
|
||
|
|
CacheScope._();
|
||
|
|
|
||
|
|
static CacheScopeProvider? _provider;
|
||
|
|
|
||
|
|
static void configureProvider(CacheScopeProvider provider) {
|
||
|
|
_provider = provider;
|
||
|
|
}
|
||
|
|
|
||
|
|
static void resetProvider() {
|
||
|
|
_provider = null;
|
||
|
|
}
|
||
|
|
|
||
|
|
static String token() {
|
||
|
|
final raw = _provider?.call()?.trim();
|
||
|
|
if (raw == null || raw.isEmpty) {
|
||
|
|
return 'anonymous';
|
||
|
|
}
|
||
|
|
return raw;
|
||
|
|
}
|
||
|
|
|
||
|
|
static String scopedKey(String key, {String? scopeToken}) {
|
||
|
|
final scope = scopeToken ?? token();
|
||
|
|
return 'cache:$scope:$key';
|
||
|
|
}
|
||
|
|
}
|