@Test public void listHotZonesCacheForSameSize() throws Exception { ZoneInfo z1 = savedZoneDefault("zone1"); savedArticle(z1, account, "foo-title"); Instant articleSince = Instant.now().minus(Duration.ofDays(20)); List<ZoneInfo> cachedForSize10 = dao.listHotZonesWithCache(10, articleSince); assertSame(cachedForSize10, dao.listHotZonesWithCache(10, articleSince)); assertNotSame(cachedForSize10, dao.listHotZonesWithCache(20, articleSince)); }
@Cacheable(value = "listHotZones", key = "#a0") public List<ZoneInfo> listHotZonesWithCache(int size, Instant articleSince) { FlakeId startArticleId = FlakeId.startOf(articleSince.toEpochMilli()); List<ZoneInfo> results = jdbc().query("" + " SELECT z.*, count(z.zone) AS zoneHotness " + " FROM Article a " + " JOIN ZoneInfo z ON z.zone = a.zone " + " WHERE a.articleId >= ? " + " AND z.hideFromTop = FALSE " + " GROUP BY z.zone " + " ORDER BY zoneHotness DESC " + " LIMIT ? ", zoneDao.getZoneInfoMapper(), startArticleId.value(), size); return ImmutableList.copyOf(results); }
ArticleDao implements DaoOperations { @Cacheable(value = "listHotZones", key = "#a0") public List<ZoneInfo> listHotZonesWithCache(int size, Instant articleSince) { FlakeId startArticleId = FlakeId.startOf(articleSince.toEpochMilli()); List<ZoneInfo> results = jdbc().query("" + " SELECT z.*, count(z.zone) AS zoneHotness " + " FROM Article a " + " JOIN ZoneInfo z ON z.zone = a.zone " + " WHERE a.articleId >= ? " + " AND z.hideFromTop = FALSE " + " GROUP BY z.zone " + " ORDER BY zoneHotness DESC " + " LIMIT ? ", zoneDao.getZoneInfoMapper(), startArticleId.value(), size); return ImmutableList.copyOf(results); } }
ArticleDao implements DaoOperations { @Cacheable(value = "listHotZones", key = "#a0") public List<ZoneInfo> listHotZonesWithCache(int size, Instant articleSince) { FlakeId startArticleId = FlakeId.startOf(articleSince.toEpochMilli()); List<ZoneInfo> results = jdbc().query("" + " SELECT z.*, count(z.zone) AS zoneHotness " + " FROM Article a " + " JOIN ZoneInfo z ON z.zone = a.zone " + " WHERE a.articleId >= ? " + " AND z.hideFromTop = FALSE " + " GROUP BY z.zone " + " ORDER BY zoneHotness DESC " + " LIMIT ? ", zoneDao.getZoneInfoMapper(), startArticleId.value(), size); return ImmutableList.copyOf(results); }  }
ArticleDao implements DaoOperations { @Cacheable(value = "listHotZones", key = "#a0") public List<ZoneInfo> listHotZonesWithCache(int size, Instant articleSince) { FlakeId startArticleId = FlakeId.startOf(articleSince.toEpochMilli()); List<ZoneInfo> results = jdbc().query("" + " SELECT z.*, count(z.zone) AS zoneHotness " + " FROM Article a " + " JOIN ZoneInfo z ON z.zone = a.zone " + " WHERE a.articleId >= ? " + " AND z.hideFromTop = FALSE " + " GROUP BY z.zone " + " ORDER BY zoneHotness DESC " + " LIMIT ? ", zoneDao.getZoneInfoMapper(), startArticleId.value(), size); return ImmutableList.copyOf(results); }  RowMapper<Article> getArticleMapper(); @Override NamedParameterJdbcTemplate namedJdbc(); Optional<Article> findArticle(FlakeId articleId); List<Article> listZoneArticlesDesc(Zone zone,
      @Nullable FlakeId startArticleId,
      int limit); List<Article> listArticlesDesc(@Nullable FlakeId startArticleId, int limit); Article createExternalLink(ZoneInfo zoneInfo,
      Account author,
      String title,
      String url,
      String canonicalUrl,
      Instant now); Article loadArticleWithoutCache(FlakeId articleId); @Cacheable("Article") Article loadArticleWithCache(FlakeId articleId); void increaseDebateCount(Article article); void changeTotalVote(FlakeId articleId, long upVoteDelta, int downVoteDelta); List<Article> listZoneHotArticles(Zone zone, @Nullable FlakeId startArticleId, int limit); List<Article> listHotArticlesExcludeHidden(@Nullable FlakeId startArticleId, int limit); @CacheEvict(value = "Article", key = "#a0.articleId") void markAsDeleted(Article article); Article createSpeak(ZoneInfo zoneInfo,
      Account author,
      String title,
      String content,
      Instant now); @VisibleForTesting @CacheEvict(value = { "listHotZones", "Article" }, allEntries = true) void evictAllCaches(); @Cacheable(value = "listHotZones", key = "#a0") List<ZoneInfo> listHotZonesWithCache(int size, Instant articleSince); List<Article> listArticlesByDebatesWithCache(List<FlakeId> debateIds); List<Article> listArticlesByAuthor(UUID authorId,
      @Nullable FlakeId startArticleId,
      int size); boolean isExternalLinkExist(Zone zone, String canonicalUrl); List<Article> listArticlesByExternalLink(Zone zone, String canonicalUrl, int size); }
ArticleDao implements DaoOperations { @Cacheable(value = "listHotZones", key = "#a0") public List<ZoneInfo> listHotZonesWithCache(int size, Instant articleSince) { FlakeId startArticleId = FlakeId.startOf(articleSince.toEpochMilli()); List<ZoneInfo> results = jdbc().query("" + " SELECT z.*, count(z.zone) AS zoneHotness " + " FROM Article a " + " JOIN ZoneInfo z ON z.zone = a.zone " + " WHERE a.articleId >= ? " + " AND z.hideFromTop = FALSE " + " GROUP BY z.zone " + " ORDER BY zoneHotness DESC " + " LIMIT ? ", zoneDao.getZoneInfoMapper(), startArticleId.value(), size); return ImmutableList.copyOf(results); }  RowMapper<Article> getArticleMapper(); @Override NamedParameterJdbcTemplate namedJdbc(); Optional<Article> findArticle(FlakeId articleId); List<Article> listZoneArticlesDesc(Zone zone,
      @Nullable FlakeId startArticleId,
      int limit); List<Article> listArticlesDesc(@Nullable FlakeId startArticleId, int limit); Article createExternalLink(ZoneInfo zoneInfo,
      Account author,
      String title,
      String url,
      String canonicalUrl,
      Instant now); Article loadArticleWithoutCache(FlakeId articleId); @Cacheable("Article") Article loadArticleWithCache(FlakeId articleId); void increaseDebateCount(Article article); void changeTotalVote(FlakeId articleId, long upVoteDelta, int downVoteDelta); List<Article> listZoneHotArticles(Zone zone, @Nullable FlakeId startArticleId, int limit); List<Article> listHotArticlesExcludeHidden(@Nullable FlakeId startArticleId, int limit); @CacheEvict(value = "Article", key = "#a0.articleId") void markAsDeleted(Article article); Article createSpeak(ZoneInfo zoneInfo,
      Account author,
      String title,
      String content,
      Instant now); @VisibleForTesting @CacheEvict(value = { "listHotZones", "Article" }, allEntries = true) void evictAllCaches(); @Cacheable(value = "listHotZones", key = "#a0") List<ZoneInfo> listHotZonesWithCache(int size, Instant articleSince); List<Article> listArticlesByDebatesWithCache(List<FlakeId> debateIds); List<Article> listArticlesByAuthor(UUID authorId,
      @Nullable FlakeId startArticleId,
      int size); boolean isExternalLinkExist(Zone zone, String canonicalUrl); List<Article> listArticlesByExternalLink(Zone zone, String canonicalUrl, int size);  }