本文整理汇总了Java中play.cache.Cache类的典型用法代码示例。如果您正苦于以下问题:Java Cache类的具体用法?Java Cache怎么用?Java Cache使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Cache类属于play.cache包,在下文中一共展示了Cache类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getAutoCompleteList
import play.cache.Cache; //导入依赖的package包/类
public static List<String> getAutoCompleteList()
{
//Logger.debug("=== Entering SearchDAO.java:getAutoCompleteList()");
List<String> cachedAutoCompleteList = (List<String>)Cache.get(SEARCH_AUTOCOMPLETE_LIST);
//Logger.debug("=== Run first query in SearchDAO.java:getAutoCompleteList()");
if (cachedAutoCompleteList == null || cachedAutoCompleteList.size() == 0)
{
//List<String> metricList = getJdbcTemplate().queryForList(GET_METRIC_AUTO_COMPLETE_LIST, String.class);
//List<String> flowList = getJdbcTemplate().queryForList(GET_FLOW_AUTO_COMPLETE_LIST, String.class);
//Logger.debug("=== Run second query in SearchDAO.java:getAutoCompleteList()");
//List<String> jobList = getJdbcTemplate().queryForList(GET_JOB_AUTO_COMPLETE_LIST, String.class);
//Logger.debug("=== Run third query in SearchDAO.java:getAutoCompleteList()");
List<String> datasetList = getJdbcTemplate().queryForList(GET_DATASET_AUTO_COMPLETE_LIST, String.class);
//Logger.debug("=== Run fourth query in SearchDAO.java:getAutoCompleteList()");
//Logger.debug("=== Run all queries in SearchDAO.java:getAutoCompleteList()");
cachedAutoCompleteList = datasetList;
Collections.sort(cachedAutoCompleteList);
Cache.set(SEARCH_AUTOCOMPLETE_LIST, cachedAutoCompleteList, 60*60);
}
Logger.trace("=== Exiting SearchDAO.java:getAutoCompleteList()");
return cachedAutoCompleteList;
}
示例2: getAutoCompleteList
import play.cache.Cache; //导入依赖的package包/类
public static List<String> getAutoCompleteList()
{
List<String> cachedAutoCompleteList = (List<String>)Cache.get(SEARCH_AUTOCOMPLETE_LIST);
if (cachedAutoCompleteList == null || cachedAutoCompleteList.size() == 0)
{
//List<String> metricList = getJdbcTemplate().queryForList(GET_METRIC_AUTO_COMPLETE_LIST, String.class);
List<String> flowList = getJdbcTemplate().queryForList(GET_FLOW_AUTO_COMPLETE_LIST, String.class);
List<String> jobList = getJdbcTemplate().queryForList(GET_JOB_AUTO_COMPLETE_LIST, String.class);
List<String> datasetList = getJdbcTemplate().queryForList(GET_DATASET_AUTO_COMPLETE_LIST, String.class);
cachedAutoCompleteList =
Stream.concat(datasetList.stream(),
Stream.concat(flowList.stream(), jobList.stream())).collect(Collectors.toList());
Collections.sort(cachedAutoCompleteList);
Cache.set(SEARCH_AUTOCOMPLETE_LIST, cachedAutoCompleteList, 60*60);
}
return cachedAutoCompleteList;
}
示例3: 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);
}
示例4: getSearchAutoComplete
import play.cache.Cache; //导入依赖的package包/类
public static Result getSearchAutoComplete() {
// if not input, then get all search names (without limit).
String input = request().getQueryString("input");
int size = 0; // size 0 means no limit
if (isNotBlank(input)) {
size = NumberUtils.toInt(request().getQueryString("size"), DEFAULT_AUTOCOMPLETE_SIZE);
}
String cacheKey = AUTOCOMPLETE_ALL_KEY + (isNotBlank(input) ? "." + input : "-all");
List<String> names = (List<String>) Cache.get(cacheKey);
if (names == null || names.size() == 0) {
names = SearchDAO.getAutoCompleteList(input, size);
Cache.set(cacheKey, names, DEFAULT_AUTOCOMPLETE_CACHE_TIME);
}
ObjectNode result = Json.newObject();
result.put("status", "ok");
result.put("input", input);
result.set("source", Json.toJson(names));
return ok(result);
}
示例5: getSearchAutoCompleteForDataset
import play.cache.Cache; //导入依赖的package包/类
public static Result getSearchAutoCompleteForDataset() {
// if not input, then get all search names (without limit).
String input = request().getQueryString("input");
int size = 0; // size 0 means no limit
if (isNotBlank(input)) {
size = NumberUtils.toInt(request().getQueryString("size"), DEFAULT_AUTOCOMPLETE_SIZE);
}
String cacheKey = AUTOCOMPLETE_DATASET_KEY + (isNotBlank(input) ? "." + input : "-all");
List<String> names = (List<String>) Cache.get(cacheKey);
if (names == null || names.size() == 0) {
names = SearchDAO.getAutoCompleteListDataset(input, size);
Cache.set(cacheKey, names, DEFAULT_AUTOCOMPLETE_CACHE_TIME);
}
ObjectNode result = Json.newObject();
result.put("status", "ok");
result.put("input", input);
result.set("source", Json.toJson(names));
return ok(result);
}
示例6: getSearchAutoCompleteForMetric
import play.cache.Cache; //导入依赖的package包/类
public static Result getSearchAutoCompleteForMetric() {
// if not input, then get all search names (without limit).
String input = request().getQueryString("input");
int size = 0; // size 0 means no limit
if (isNotBlank(input)) {
size = NumberUtils.toInt(request().getQueryString("size"), DEFAULT_AUTOCOMPLETE_SIZE);
}
String cacheKey = AUTOCOMPLETE_METRIC_KEY + (isNotBlank(input) ? "." + input : "-all");
List<String> names = (List<String>) Cache.get(cacheKey);
if (names == null || names.size() == 0) {
names = SearchDAO.getAutoCompleteListMetric(input, size);
Cache.set(cacheKey, names, DEFAULT_AUTOCOMPLETE_CACHE_TIME);
}
ObjectNode result = Json.newObject();
result.put("status", "ok");
result.put("input", input);
result.set("source", Json.toJson(names));
return ok(result);
}
示例7: getSearchAutoCompleteForFlow
import play.cache.Cache; //导入依赖的package包/类
public static Result getSearchAutoCompleteForFlow() {
// if not input, then get all search names (without limit).
String input = request().getQueryString("input");
int size = 0; // size 0 means no limit
if (isNotBlank(input)) {
size = NumberUtils.toInt(request().getQueryString("size"), DEFAULT_AUTOCOMPLETE_SIZE);
}
String cacheKey = AUTOCOMPLETE_FLOW_KEY + (isNotBlank(input) ? "." + input : "-all");
List<String> names = (List<String>) Cache.get(cacheKey);
if (names == null || names.size() == 0) {
names = SearchDAO.getAutoCompleteListFlow(input, size);
Cache.set(cacheKey, names, DEFAULT_AUTOCOMPLETE_CACHE_TIME);
}
ObjectNode result = Json.newObject();
result.put("status", "ok");
result.put("input", input);
result.set("source", Json.toJson(names));
return ok(result);
}
示例8: local
import play.cache.Cache; //导入依赖的package包/类
/**
* Get a local asset by path.
*
* @param assetsRootLocation
* the assets root location
* @param path
* the file path of the asset
*/
public static String local(String assetsRootLocation, String path) {
String cacheKey = CACHE_PREFIX + path;
String fileChecksum = (String) Cache.get(cacheKey);
if (fileChecksum == null) {
try {
fileChecksum = getFileChecksumByPath(path);
} catch (Exception e) {
Logger.error("AssetsVersion/local: error when getting the checksum for the path " + path, e);
fileChecksum = UUID.randomUUID().toString();
}
Cache.set(cacheKey, fileChecksum);
}
return assetsRootLocation + path + "?" + fileChecksum;
}
示例9: downloadFileAttachment
import play.cache.Cache; //导入依赖的package包/类
/**
* This method is to be integrated within a controller.<br/>
* It looks for the specified attachment and returns it if the user is
* allowed to access it.
*
* @param attachmentId
* the id of an attachment
* @param attachmentManagerPlugin
* the service which is managing attachments
* @param sessionManagerPlugin
* the service which is managing user sessions
* @return the attachment as a stream
*/
public static Result downloadFileAttachment(Long attachmentId, IAttachmentManagerPlugin attachmentManagerPlugin,
IUserSessionManagerPlugin sessionManagerPlugin) {
@SuppressWarnings("unchecked")
Set<Long> allowedIds = (Set<Long>) Cache
.get(IFrameworkConstants.ATTACHMENT_READ_AUTHZ_CACHE_PREFIX + sessionManagerPlugin.getUserSessionId(Controller.ctx()));
if (allowedIds != null && allowedIds.contains(attachmentId)) {
try {
Attachment attachment = attachmentManagerPlugin.getAttachmentFromId(attachmentId);
if (attachment.mimeType.equals(FileAttachmentHelper.FileType.URL.name())) {
return Controller.redirect(attachment.path);
} else {
Controller.response().setHeader("Content-Disposition", "attachment; filename=\"" + attachment.name + "\"");
return Controller.ok(attachmentManagerPlugin.getAttachmentContent(attachmentId));
}
} catch (IOException e) {
log.error("Error while retreiving the attachment content for " + attachmentId);
return Controller.badRequest();
}
}
return Controller.badRequest();
}
示例10: deleteFileAttachment
import play.cache.Cache; //导入依赖的package包/类
/**
* This method is to be integrated within a controller.<br/>
* It looks for the specified attachment and delete it if the user is
* allowed to erase it.<br/>
* It is to be called by an AJAX GET with a single attribute : the id of the
* attachment.
*
* @param attachmentId
* the id of an attachment
* @param attachmentManagerPlugin
* the service which is managing attachments
* @param sessionManagerPlugin
* the service which is managing user sessions
* @return the result
*/
public static Result deleteFileAttachment(Long attachmentId, IAttachmentManagerPlugin attachmentManagerPlugin,
IUserSessionManagerPlugin sessionManagerPlugin) {
@SuppressWarnings("unchecked")
Set<Long> allowedIds = (Set<Long>) Cache
.get(IFrameworkConstants.ATTACHMENT_WRITE_AUTHZ_CACHE_PREFIX + sessionManagerPlugin.getUserSessionId(Controller.ctx()));
if (allowedIds != null && allowedIds.contains(attachmentId)) {
try {
attachmentManagerPlugin.deleteAttachment(attachmentId);
return Controller.ok();
} catch (IOException e) {
log.error("Error while deleting the attachment content for " + attachmentId);
return Controller.badRequest();
}
}
return Controller.badRequest();
}
示例11: getLocationByCoordinates
import play.cache.Cache; //导入依赖的package包/类
/**
* Retrieve location by coordinates
* Example URL http://maps.googleapis.com/maps/api/geocode/json?latlng=40.714224,-73.961452&sensor=false&language=en
* @param sLon
* @param sLat
* @return
* @throws UnsupportedEncodingException
*/
public static Promise<Location> getLocationByCoordinates(String sLon, String sLat) throws UnsupportedEncodingException{
@SuppressWarnings("unchecked")
Promise<Location> loc = (Promise<Location>) Cache.get(CACHE_GEO+sLat+sLon);
if(loc == null)
loc = getLocationByURL("http://maps.googleapis.com/maps/api/geocode/xml?latlng="+sLon+","+sLat+"&sensor=false&language=en");
Cache.set(CACHE_GEO+sLat+sLon, loc);
return loc;
}
示例12: 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;
}
示例13: 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;
}
示例14: getNumberOfUnreadMessages
import play.cache.Cache; //导入依赖的package包/类
/**
* Get number of unread messages for the current user
* @return
*/
public int getNumberOfUnreadMessages() {
// TODO: use injected context for this
int userId = CurrentUser.getId();
String key = String.format(MESSAGE_NUMBER_BY_ID, userId);
Object obj = Cache.get(key);
if (obj == null || !(obj instanceof List)) {
try (DataAccessContext context = provider.getDataAccessContext()) {
int unread_number = context.getMessageDAO().countUnreadMessagesTo(userId);
Cache.set(key, unread_number);
return unread_number;
}
} else {
return (Integer) obj; //Type erasure problem from Java, works at runtime
}
}
示例15: getMainCache
import play.cache.Cache; //导入依赖的package包/类
/**
* This is the main cache object. It contains a single entry for every
* scope. The values of these entries are another map, containing key/value
* entries for that scope
*/
private static Map<Scope, Map<UUID, Map<Object, CacheValue>>> getMainCache()
{
Map<Scope, Map<UUID, Map<Object, CacheValue>>> retVal = (Map<Scope, Map<UUID, Map<Object, CacheValue>>>) Cache.get(SERVER_CACHE_MAP_KEY);
// bootstrap an empty cache if it's not present (eg. after a server
// reboot)
if (retVal == null) {
retVal = new HashMap<Scope, Map<UUID, Map<Object, CacheValue>>>();
retVal.put(Scope.REQUEST, new HashMap<UUID, Map<Object, CacheValue>>());
retVal.put(Scope.SESSION, new HashMap<UUID, Map<Object, CacheValue>>());
retVal.put(Scope.APPLICATION, new HashMap<UUID, Map<Object, CacheValue>>());
// store our new cache in the Cache API
Cache.set(SERVER_CACHE_MAP_KEY, retVal);
}
// let's use this opportunity to purge the cache
Cacher.checkPurgeCache(retVal);
return retVal;
}