From db0762ad3f792806b3aa5cf54e230e57a4ed9e8d Mon Sep 17 00:00:00 2001 From: Karthikeyan S Date: Wed, 13 Dec 2023 18:28:44 +0530 Subject: [PATCH] feat: cache getConfig request --- lib/src/client.dart | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/src/client.dart b/lib/src/client.dart index 770a4be2..cbfc857c 100644 --- a/lib/src/client.dart +++ b/lib/src/client.dart @@ -22,6 +22,7 @@ import 'dart:core'; import 'dart:math'; import 'dart:typed_data'; +import 'package:async/async.dart'; import 'package:collection/collection.dart' show IterableExtension; import 'package:http/http.dart' as http; import 'package:mime/mime.dart'; @@ -1011,6 +1012,13 @@ class Client extends MatrixApi { _archivedRooms.add(ArchivedRoom(room: archivedRoom, timeline: timeline)); } + final _serverConfigCache = AsyncCache(const Duration(hours: 1)); + + /// Gets the config of the content repository, such as upload limit. + @override + Future getConfig() => + _serverConfigCache.fetch(() => super.getConfig()); + /// Uploads a file and automatically caches it in the database, if it is small enough /// and returns the mxc url. @override @@ -1477,6 +1485,7 @@ class Client extends MatrixApi { } _groupCallSessionId = randomAlpha(12); + _serverConfigCache.invalidate(); String? olmAccount; String? accessToken;