删除播放缓存中的单个项

2hh7jdfx  于 2021-07-14  发布在  Java
关注(0)|答案(1)|浏览(240)

我正在PlayScala(2.5)应用程序中使用缓存。我想所有的东西都保持缓存,除了新的食谱-这些我想被抓取新鲜的每一次。如何从缓存中删除单个项(newrecipes)?

package controllers

import javax.inject.{Inject, Singleton}

import models.Menu.MainMenus
import models.PrismicAPI.Prismic
import models.Products.{IndivProduct, NewProducts}
import models.Promotions.{RegularPromotions, ShortDatedPromotions}
import play.api.cache.Cached
import play.api.libs.concurrent.Execution.Implicits.defaultContext
import play.api.mvc.Controller

@Singleton
class FrontPage @Inject()(cached: Cached
                      , prismic: Prismic
                      , newProducts: NewProducts
                      , recipes: models.Recipes.Recipes
                      , mainMenu: MainMenus
                      , regularPromotions: RegularPromotions
                      , shortDatedPromotions: ShortDatedPromotions
                     ) extends Controller {

def landing(q: Option[String]) = cached("frontpage" + q) {

prismic.action() { implicit request =>
  for {
    topMenu <- mainMenu.futureMainMenu()
    footer <- models.FooterPDFs.futureFooterPDFs()
    carouselImages <- models.FrontPage.CarouselImage.futureCarouselImages()
    content <- models.FrontPage.FrontPageContent.futureFrontPageContent()
    taggedDocs <- models.FrontPage.FrontPage.frontPageTaggedDocs()
    newRecipes <- recipes.futureFrontPageRecipes(taggedDocs.filter(_.typ == "recipe"))
    newProducts <- newProducts.loadNewProducts(taggedDocs.filter(_.typ == "new-product"))
    recentNews <- models.News.NewsArticle.loadNewsArticles(taggedDocs.filter(_.typ == "news-article"))
    regularPromos <- regularPromotions.loadRegularPromos(taggedDocs.filter(_.typ == "regular-promotion"))
        shortPromos <- shortDatedPromotions.loadShortPromos(taggedDocs.filter(_.typ == "short-dated-promotion"))
      } yield {
....
k3fezbri

k3fezbri1#

有关更多帮助,请参阅官方文档:https://www.playframework.com/documentation/2.6.x/scalacache#accessing-缓存api

val removeResult: Future[Done] = cache.remove("item.key")

相关问题