From: Mark Herwege Date: Thu, 27 Jun 2024 06:58:11 +0000 (+0200) Subject: [inmemory] Default persistence strategy Forecast (#16496) X-Git-Url: https://git.basschouten.com/?a=commitdiff_plain;h=b8c04ae42453a1f7492e46d1ee5ced3022d7dde1;p=openhab-addons.git [inmemory] Default persistence strategy Forecast (#16496) * default forecast persistence strategy Signed-off-by: Mark Herwege --- diff --git a/bundles/org.openhab.persistence.inmemory/README.md b/bundles/org.openhab.persistence.inmemory/README.md index f24ab44c85..ec4f0a4adf 100644 --- a/bundles/org.openhab.persistence.inmemory/README.md +++ b/bundles/org.openhab.persistence.inmemory/README.md @@ -5,7 +5,7 @@ Because of that the `restoreOnStartup` strategy is not supported for this servic The main use-case is to store data that is needed during runtime, e.g. temporary storage of forecast data that is retrieved from a binding. -Since all data is stored in memory only, there is no default strategy for this service. +The default strategy for this service is `forecast`. Unlike other persistence services, you MUST add a configuration, otherwise no data will be persisted. To avoid excessive memory usage, it is recommended to persist only a limited number of items and use a strategy that stores only data that is actually needed. diff --git a/bundles/org.openhab.persistence.inmemory/src/main/java/org/openhab/persistence/inmemory/internal/InMemoryPersistenceService.java b/bundles/org.openhab.persistence.inmemory/src/main/java/org/openhab/persistence/inmemory/internal/InMemoryPersistenceService.java index 0caf9721fb..3b0d69ad5a 100644 --- a/bundles/org.openhab.persistence.inmemory/src/main/java/org/openhab/persistence/inmemory/internal/InMemoryPersistenceService.java +++ b/bundles/org.openhab.persistence.inmemory/src/main/java/org/openhab/persistence/inmemory/internal/InMemoryPersistenceService.java @@ -188,8 +188,8 @@ public class InMemoryPersistenceService implements ModifiablePersistenceService @Override public List getDefaultStrategies() { - // persist nothing by default - return List.of(); + // persist only forecasts by default + return List.of(PersistenceStrategy.Globals.FORECAST); } private PersistenceItemInfo toItemInfo(Map.Entry itemEntry) { @@ -268,7 +268,7 @@ public class InMemoryPersistenceService implements ModifiablePersistenceService } } - @SuppressWarnings({ "rawType", "unchecked" }) + @SuppressWarnings("unchecked") private boolean applies(PersistEntry entry, FilterCriteria filter) { ZonedDateTime beginDate = filter.getBeginDate(); if (beginDate != null && beginDate.isAfter(entry.timestamp())) {