当前位置: 首页>>代码示例>>Java>>正文


Java Cache.getOrElse方法代码示例

本文整理汇总了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);
}
 
开发者ID:Telecooperation,项目名称:assistance-platform-server,代码行数:17,代码来源:AssistanceController.java

示例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;
}
 
开发者ID:fmaturel,项目名称:PlayTraining,代码行数:21,代码来源:Frontoffice.java

示例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;
}
 
开发者ID:fmaturel,项目名称:PlayTraining,代码行数:22,代码来源:Frontoffice.java

示例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);
}
 
开发者ID:hakandilek,项目名称:play2-crud,代码行数:23,代码来源:RouterController.java

示例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);
}
 
开发者ID:fmaturel,项目名称:PlayTraining,代码行数:18,代码来源:Frontoffice.java

示例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);
}
 
开发者ID:fmaturel,项目名称:PlayTraining,代码行数:19,代码来源:Frontoffice.java

示例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;
	}
}
 
开发者ID:hakandilek,项目名称:play2-crud,代码行数:25,代码来源:InterimCache.java

示例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;
	}
}
 
开发者ID:hakandilek,项目名称:play2-crud,代码行数:25,代码来源:InterimCache.java

示例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);
	}
}
 
开发者ID:hakandilek,项目名称:play2-crud,代码行数:15,代码来源:CachedFinder.java

示例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);
	}
}
 
开发者ID:hakandilek,项目名称:play2-crud,代码行数:15,代码来源:CachedFinder.java

示例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();
	}
}
 
开发者ID:hakandilek,项目名称:play2-crud,代码行数:14,代码来源:CachedFinder.java

示例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());
    }
}
 
开发者ID:Sonat-Consulting,项目名称:javabin-play-public,代码行数:9,代码来源:Twitter.java


注:本文中的play.cache.Cache.getOrElse方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。