本文整理汇总了Java中play.cache.Cache.getOrElse方法的典型用法代码示例。如果您正苦于以下问题:Java Cache.getOrElse方法的具体用法?Java Cache.getOrElse怎么用?Java Cache.getOrElse使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类play.cache.Cache
的用法示例。
在下文中一共展示了Cache.getOrElse方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: list
import play.cache.Cache; //导入方法依赖的package包/类
@Security.Authenticated(UserAuthenticator.class)
public Result list(String language) {
JsonNode result = Cache
.getOrElse(
"moduleList" + language,
() -> {
ActiveAssistanceModule[] assiModules = ActiveAssistanceModulePersistency
.list(language);
JsonNode json = Json.toJson(assiModules);
return json;
}, 3600);
return ok(result);
}
示例2: list
import play.cache.Cache; //导入方法依赖的package包/类
/**
* Get the list of {@link Film}.
*
* @throws Exception
*/
// @Cached(key = "list", duration = DURATION) => Pose un problème car ne tient pas compte du paramètrage
@BodyParser.Of(BodyParser.Json.class)
@play.db.jpa.Transactional(readOnly = true)
public static Result list(final String genre, final int size) throws Exception {
PerfLogger perf = PerfLogger.start("http.frontoffice.list[{}]", genre + "," + size);
Result result = Cache.getOrElse("list." + genre + ".size" + size, new Callable<Result>() {
@Override
public Result call() throws Exception {
play.Logger.info("La requête [{}] ne fait pas appel au Cache", request().path());
return ok(Json.toJson(Film.findBy(genre, size)));
}
}, DURATION);
perf.stop();
return result;
}
示例3: get
import play.cache.Cache; //导入方法依赖的package包/类
/**
* Get a {@link Film} by id.<br>
* Can use @Cached annotation as
*
* @throws Exception
*/
// @Cached(key = "detail", duration = DURATION) => Pose un problème car ne tient pas compte du paramètrage
@BodyParser.Of(BodyParser.Json.class)
@play.db.jpa.Transactional(readOnly = true)
public static Result get(final Long id) throws Exception {
PerfLogger perf = PerfLogger.start("http.frontoffice.get[{}]", id);
Result result = Cache.getOrElse("detail." + id, new Callable<Result>() {
@Override
public Result call() throws Exception {
play.Logger.info("La requête [{}] ne fait pas appel au Cache", request().path());
return ok(Json.toJson(Film.findById(id)));
}
}, DURATION);
perf.stop();
return result;
}
示例4: getModel
import play.cache.Cache; //导入方法依赖的package包/类
protected F.Option<ModelMetadata> getModel(final String name) {
ModelMetadata modelInfo = null;
try {
modelInfo = (ModelMetadata) Cache.getOrElse(getClass().getName() + "_ModelMetadata_" + name,
new Callable<Object>() {
@Override
public Object call() throws Exception {
return Iterables.find(modelRegistry.getModels(), new Predicate<ModelMetadata>() {
@Override
public boolean apply(ModelMetadata model) {
String modelName = model.getName();
return modelName.equals(name);
}
}, null);
}
}, 0);
} catch (Exception e) {
e.printStackTrace();
}
return modelInfo == null ? F.Option.<ModelMetadata> None() : F.Option.Some(modelInfo);
}
示例5: list
import play.cache.Cache; //导入方法依赖的package包/类
/**
* Get the list of {@link Film}.
*
* @throws Exception
*/
// @Cached(key = "list", duration = DURATION) => Pose un problème car ne tient pas compte du paramètrage
@BodyParser.Of(BodyParser.Json.class)
@play.db.jpa.Transactional(readOnly = true)
public static Result list(final String genre, final int size) throws Exception {
return Cache.getOrElse("list." + genre + ".size" + size, new Callable<Result>() {
@Override
public Result call() throws Exception {
play.Logger.info("La requête [{}] ne fait pas appel au Cache", request().path());
return ok(Json.toJson(Film.findBy(genre, size)));
}
}, DURATION);
}
示例6: get
import play.cache.Cache; //导入方法依赖的package包/类
/**
* Get a {@link Film} by id.<br>
* Can use @Cached annotation as
*
* @throws Exception
*/
// @Cached(key = "detail", duration = DURATION) => Pose un problème car ne tient pas compte du paramètrage
@BodyParser.Of(BodyParser.Json.class)
@play.db.jpa.Transactional(readOnly = true)
public static Result get(final Long id) throws Exception {
return Cache.getOrElse("detail." + id, new Callable<Result>() {
@Override
public Result call() throws Exception {
play.Logger.info("La requête [{}] ne fait pas appel au Cache", request().path());
return ok(Json.toJson(Film.findById(id)));
}
}, DURATION);
}
示例7: page
import play.cache.Cache; //导入方法依赖的package包/类
/**
* Creates and caches the page with the given creator
*
* @param id
* unique cache id
* @param pageCreator
* page creator callback object
* @return the cached page if one exists, otherwise creates a new one and
* caches it.
*/
public Page<T> page(String id, Callable<Page<T>> pageCreator) {
String key = prefix + id;
if (Logger.isDebugEnabled())
Logger.debug("key : " + key);
try {
Page<T> p = Cache.getOrElse(key, pageCreator, timeout);
if (Logger.isDebugEnabled())
Logger.debug("p : " + p);
return p;
} catch (Exception e) {
log.error("exception occured while retrieving from cache", e);
return null;
}
}
示例8: get
import play.cache.Cache; //导入方法依赖的package包/类
/**
* Creates and caches the page with the given creator
*
* @param id
* unique cache id
* @param creator
* page creator callback object
* @return the cached page if one exists, otherwise creates a new one and
* caches it.
*/
public T get(String id, Callable<T> creator) {
String key = prefix + id;
if (Logger.isDebugEnabled())
Logger.debug("key : " + key);
try {
T t = Cache.getOrElse(key, creator, timeout);
if (Logger.isDebugEnabled())
Logger.debug("t : " + t);
return t;
} catch (Exception e) {
log.error("exception occured while retrieving from cache", e);
return null;
}
}
示例9: byId
import play.cache.Cache; //导入方法依赖的package包/类
@Override
public T byId(final K id) {
String key = pre + id;
try {
return Cache.getOrElse(key, new Callable<T>() {
public T call() throws Exception {
return CachedFinder.super.byId(id);
}
}, EXPIRATION);
} catch (Exception e) {
log.error("exception occured while retrieving from cache", e);
return super.byId(id);
}
}
示例10: ref
import play.cache.Cache; //导入方法依赖的package包/类
@Override
public T ref(final K id) {
String key = pre + id;
try {
return Cache.getOrElse(key, new Callable<T>() {
public T call() throws Exception {
return CachedFinder.super.ref(id);
}
}, EXPIRATION);
} catch (Exception e) {
log.error("exception occured while retrieving from cache", e);
return super.ref(id);
}
}
示例11: all
import play.cache.Cache; //导入方法依赖的package包/类
@Override
public List<T> all() {
try {
return Cache.getOrElse(keyAll, new Callable<List<T>>() {
public List<T> call() throws Exception {
return CachedFinder.super.all();
}
}, EXPIRATION);
} catch (Exception e) {
log.error("exception occured while retrieving from cache", e);
return super.all();
}
}
示例12: search
import play.cache.Cache; //导入方法依赖的package包/类
public static Result search(final String searchTerm, final String geoCode) {
try {
return Cache.getOrElse(String.format("twitterSearch?q=%1$s,geocode=%2$s", searchTerm, geoCode),
new TwitterSearchCallable(searchTerm, geoCode), CACHE_EXPIRATION_TWITTER_SEARCH);
} catch (Exception e) {
return internalServerError(e.getMessage());
}
}