diff --git a/config.yml b/config.yml index 17d4227a..6941c882 100644 --- a/config.yml +++ b/config.yml @@ -18,6 +18,7 @@ app: crawlingPaused: false keepStatusDays: 0 refreshIntervalMinutes: 5 + cache: noop announcement: authenticationCachePolicy: maximumSize=10000, expireAfterAccess=10m diff --git a/src/main/java/com/commafeed/CommaFeedApplication.java b/src/main/java/com/commafeed/CommaFeedApplication.java index 422b51d0..0050ad69 100644 --- a/src/main/java/com/commafeed/CommaFeedApplication.java +++ b/src/main/java/com/commafeed/CommaFeedApplication.java @@ -10,12 +10,16 @@ import io.dropwizard.setup.Environment; import java.util.Date; +import lombok.extern.slf4j.Slf4j; + import org.hibernate.SessionFactory; import com.codahale.metrics.MetricRegistry; +import com.commafeed.CommaFeedConfiguration.CacheType; import com.commafeed.backend.HttpGetter; import com.commafeed.backend.cache.CacheService; import com.commafeed.backend.cache.NoopCacheService; +import com.commafeed.backend.cache.RedisCacheService; import com.commafeed.backend.dao.FeedCategoryDAO; import com.commafeed.backend.dao.FeedDAO; import com.commafeed.backend.dao.FeedEntryContentDAO; @@ -68,6 +72,7 @@ import com.commafeed.frontend.resource.ServerREST; import com.commafeed.frontend.resource.UserREST; import com.commafeed.frontend.servlet.NextUnreadServlet; +@Slf4j public class CommaFeedApplication extends Application { public static final String USERNAME_ADMIN = "admin"; @@ -106,8 +111,9 @@ public class CommaFeedApplication extends Application { MetricRegistry metrics = environment.metrics(); SessionFactory sessionFactory = hibernateBundle.getSessionFactory(); - // TODO select cache service at runtime from config - CacheService cacheService = new NoopCacheService(); + CacheService cacheService = config.getApplicationSettings().getCache() == CacheType.NOOP ? new NoopCacheService() + : new RedisCacheService(); + log.info("using cache {}", cacheService.getClass()); FeedCategoryDAO feedCategoryDAO = new FeedCategoryDAO(sessionFactory); FeedDAO feedDAO = new FeedDAO(sessionFactory); diff --git a/src/main/java/com/commafeed/CommaFeedConfiguration.java b/src/main/java/com/commafeed/CommaFeedConfiguration.java index c71394ea..4b9abc6f 100644 --- a/src/main/java/com/commafeed/CommaFeedConfiguration.java +++ b/src/main/java/com/commafeed/CommaFeedConfiguration.java @@ -18,6 +18,10 @@ import com.google.common.cache.CacheBuilderSpec; @Getter public class CommaFeedConfiguration extends Configuration { + public static enum CacheType { + NOOP, REDIS + } + @Valid @NotNull @JsonProperty("database") @@ -92,6 +96,9 @@ public class CommaFeedConfiguration extends Configuration { @JsonProperty private int refreshIntervalMinutes; + @JsonProperty + private CacheType cache; + @JsonProperty private String announcement;