Skip to content

Commit

Permalink
Merge pull request #12924 from SORMAS-Foundation/feature-12804-custom…
Browse files Browse the repository at this point in the history
…_enum_cache_app

#12804 - Reset cache when pulling new values
  • Loading branch information
leventegal-she authored Jan 31, 2024
2 parents 2e233ba + a03dd89 commit 9270c3d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,11 @@ public <T extends CustomizableEnum> List<T> getEnumValues(CustomizableEnumType t
.collect(Collectors.toList());
}

public boolean hasEnumValues(CustomizableEnumType type, Disease disease) {
return !getEnumValues(type, disease).isEmpty();
public void clearCache() {
customizableEnumsByType.clear();
enumValuesByLanguage.clear();
enumValuesByDisease.clear();
enumInfo.clear();
}

private <T extends CustomizableEnum> void initCaches(CustomizableEnumType type, Language language) {
Expand Down Expand Up @@ -205,10 +208,7 @@ private <T extends CustomizableEnum> void addValuesByDisease(CustomizableEnumTyp
}

private void loadData() {
customizableEnumsByType.clear();
enumValuesByLanguage.clear();
enumValuesByDisease.clear();
enumInfo.clear();
clearCache();

for (CustomizableEnumType enumType : CustomizableEnumType.values()) {
customizableEnumsByType.putIfAbsent(enumType, new ArrayList<>());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import de.symeda.sormas.api.PostResponse;
import de.symeda.sormas.api.customizableenum.CustomizableEnumValueDto;
import de.symeda.sormas.app.backend.common.AdoDtoHelper;
import de.symeda.sormas.app.backend.common.DatabaseHelper;
import de.symeda.sormas.app.rest.NoConnectionException;
import de.symeda.sormas.app.rest.RetroProvider;
import retrofit2.Call;
Expand Down Expand Up @@ -70,6 +71,14 @@ public void fillInnerFromAdo(CustomizableEnumValueDto target, CustomizableEnumVa
// Not supported
}

@Override
protected void executeHandlePulledListAddition(int listSize) {
if (listSize > 0) {
// Clear the customizable enum value cache if values have changed
DatabaseHelper.getCustomizableEnumValueDao().clearCache();
}
}

@Override
protected long getApproximateJsonSizeInBytes() {
return 0;
Expand Down

0 comments on commit 9270c3d

Please sign in to comment.