app.getWrappedApplication().injector().instanceOf(javaguide.cache.qualified.Application.class);
}
@Test
public void simple() {
CacheApi cache = app.getWrappedApplication().injector().instanceOf(CacheApi.class);
News frontPageNews = new News();
//#simple-set
cache.set("item.key", frontPageNews);
//#simple-set
//#time-set
// Cache for 15 minutes
cache.set("item.key", frontPageNews, 60 * 15);
//#time-set
//#get
News news = cache.get("item.key");
//#get
assertThat(news, equalTo(frontPageNews));
//#get-or-else
News maybeCached = cache.getOrElse("item.key", new Callable<News>() {
public News call() {
return lookUpFrontPageNews();
}
});
//#get-or-else
//#remove
cache.remove("item.key");
//#remove
assertThat(cache.get("item.key"), nullValue());
}