|
|
@ -1,10 +1,9 @@ |
|
|
|
part of '../harbour.dart'; |
|
|
|
part of '../harbour.dart'; |
|
|
|
|
|
|
|
|
|
|
|
class RequestManager { |
|
|
|
class RequestManager { |
|
|
|
RequestManager(final HarbourPlatform platform) { |
|
|
|
RequestManager(this._cache); |
|
|
|
_cache = Cache(platform); |
|
|
|
|
|
|
|
} |
|
|
|
final Cache _cache; |
|
|
|
late final Cache _cache; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final bool _enablePrinting = false; |
|
|
|
final bool _enablePrinting = false; |
|
|
|
|
|
|
|
|
|
|
@ -182,7 +181,7 @@ class Cache { |
|
|
|
final HarbourPlatform _platform; |
|
|
|
final HarbourPlatform _platform; |
|
|
|
Database? _database; |
|
|
|
Database? _database; |
|
|
|
|
|
|
|
|
|
|
|
Future _ensureInitialized() async { |
|
|
|
Future init() async { |
|
|
|
if (_database != null) { |
|
|
|
if (_database != null) { |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
@ -199,27 +198,17 @@ class Cache { |
|
|
|
); |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Future<bool> has(final String key) async { |
|
|
|
Future<bool> has(final String key) async => |
|
|
|
await _ensureInitialized(); |
|
|
|
Sqflite.firstIntValue(await _database!.rawQuery('SELECT COUNT(*) FROM cache WHERE key = ?', [key])) == 1; |
|
|
|
|
|
|
|
|
|
|
|
return Sqflite.firstIntValue(await _database!.rawQuery('SELECT COUNT(*) FROM cache WHERE key = ?', [key])) == 1; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Future<String?> get(final String key) async { |
|
|
|
|
|
|
|
await _ensureInitialized(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return (await _database!.rawQuery('SELECT value FROM cache WHERE key = ?', [key]))[0]['value'] as String?; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Future set(final String key, final String value) async { |
|
|
|
Future<String?> get(final String key) async => |
|
|
|
await _ensureInitialized(); |
|
|
|
(await _database!.rawQuery('SELECT value FROM cache WHERE key = ?', [key]))[0]['value'] as String?; |
|
|
|
|
|
|
|
|
|
|
|
await _database!.rawQuery( |
|
|
|
Future set(final String key, final String value) async => _database!.rawQuery( |
|
|
|
'INSERT INTO cache (key, value) VALUES (?, ?) ON CONFLICT(key) DO UPDATE SET value = excluded.value', |
|
|
|
'INSERT INTO cache (key, value) VALUES (?, ?) ON CONFLICT(key) DO UPDATE SET value = excluded.value', |
|
|
|
[key, value], |
|
|
|
[key, value], |
|
|
|
); |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ResultCached<T> implements Result<T> { |
|
|
|
class ResultCached<T> implements Result<T> { |
|
|
|
ResultCached( |
|
|
|
ResultCached( |
|
|
|