-
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.
feat(frontend): Simple in memory cache for tagger client
- Loading branch information
Showing
2 changed files
with
64 additions
and
4 deletions.
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
frontend/lib/api/tagger/repository_tagger_cache_client.dart
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,51 @@ | ||
import 'package:flutter/foundation.dart'; | ||
|
||
import 'repository_tagger_client.dart'; | ||
|
||
|
||
/// Simple tagger client cache layer | ||
class RepositoryTaggerCacheClient implements RepositoryTaggerClient { | ||
RepositoryTaggerCacheClient({ | ||
@required this.delegate, | ||
}); | ||
|
||
final RepositoryTaggerClient delegate; | ||
|
||
List<SimpleRepository> _cachedStarredRepos = []; | ||
|
||
@override | ||
Future<UserTag> addTag(CreateTagInput input) => delegate.addTag(input); | ||
|
||
@override | ||
Future<DetailedRepository> detailedRepo(int id) => delegate.detailedRepo(id); | ||
|
||
@override | ||
Future<bool> hasSession() => delegate.hasSession(); | ||
|
||
@override | ||
Future<String> oauth() => delegate.oauth(); | ||
|
||
@override | ||
Future removeTag({int githubId, int userTagId}) => delegate.removeTag( | ||
githubId: githubId, | ||
userTagId: userTagId, | ||
); | ||
|
||
@override | ||
Future<TagRepositoriesResponse> repositoriesByTag(int id) => | ||
delegate.repositoriesByTag(id); | ||
|
||
@override | ||
Future<List<SimpleRepository>> starredRepos() async { | ||
if (_cachedStarredRepos.isEmpty) { | ||
final repos = await delegate.starredRepos(); | ||
|
||
_cachedStarredRepos = repos; | ||
} | ||
|
||
return _cachedStarredRepos; | ||
} | ||
|
||
@override | ||
Future<List<UserTag>> userTags() => delegate.userTags(); | ||
} |
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