clear all server caches after leaving modslayer

This commit is contained in:
HJfod 2024-03-23 18:10:54 +02:00
parent ece3fd22d8
commit 98dc9f51cd
3 changed files with 15 additions and 4 deletions

View file

@ -75,6 +75,8 @@ namespace server {
std::optional<std::string> developer;
size_t page = 0;
size_t pageSize = 10;
bool operator==(ModsQuery const& other) const = default;
};
struct ServerError {
@ -199,14 +201,14 @@ namespace server {
Cache m_cache;
public:
static ServerResultCache<F>& shared() {
static ServerResultCache& shared() {
static auto inst = ServerResultCache();
static auto _ = listenForSettingChanges<int64_t>("server-cache-size-limit", +[](int64_t size) {
ServerResultCache::shared().setSizeLimit(size);
});
return inst;
}
ServerPromise<Result> get(Query const& query) {
return m_cache.get(query);
}
@ -225,4 +227,11 @@ namespace server {
m_cache.limit(size);
}
};
// Clear all shared server endpoint caches
static void clearServerCaches() {
ServerResultCache<&getMods>::shared().invalidateAll();
ServerResultCache<&getMod>::shared().invalidateAll();
ServerResultCache<&getModLogo>::shared().invalidateAll();
}
}

View file

@ -89,7 +89,7 @@ static auto loadInstalledModsPage(server::ModsQuery&& query) {
}
static auto loadServerModsPage(server::ModsQuery&& query) {
return server::getMods(query)
return server::ServerResultCache<&server::getMods>::shared().get(query)
.then<ModListSource::ProvidedMods>([](server::ServerModsList list) {
auto content = ModListSource::ProvidedMods();
for (auto&& mod : std::move(list.mods)) {

View file

@ -264,7 +264,9 @@ void ModsLayer::onRefreshList(CCObject*) {
void ModsLayer::onBack(CCObject*) {
CCDirector::get()->replaceScene(CCTransitionFade::create(.5f, MenuLayer::scene(false)));
server::ServerResultCache<&server::getModLogo>::shared().invalidateAll();
// To avoid memory overloading, clear caches after leaving the layer
server::clearServerCaches();
}
void ModsLayer::onGoToPage(CCObject*) {