本文整理汇总了Java中play.cache.Cache.get方法的典型用法代码示例。如果您正苦于以下问题:Java Cache.get方法的具体用法?Java Cache.get怎么用?Java Cache.get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类play.cache.Cache
的用法示例。
在下文中一共展示了Cache.get方法的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: 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);
}
示例4: 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);
}
示例5: 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();
}
示例6: 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();
}
示例7: local
import play.cache.Cache; //导入方法依赖的package包/类
/**
* Get a local asset by url.
*
* @param url
* the relative url of the asset
*/
public static String local(String url) {
String cacheKey = CACHE_PREFIX + url;
String fileChecksum = (String) Cache.get(cacheKey);
if (fileChecksum == null) {
try {
fileChecksum = getFileChecksumByUrl(Play.application().configuration().getString("maf.private.url") + url);
} catch (Exception e) {
Logger.error("AssetsVersion/local: error when getting the checksum for the url " + url, e);
fileChecksum = UUID.randomUUID().toString();
}
Cache.set(cacheKey, fileChecksum);
}
return url + "?" + fileChecksum;
}
示例8: 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
}
}
示例9: 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;
}
示例10: wsCall
import play.cache.Cache; //导入方法依赖的package包/类
public static WebSocket<String> wsCall() {
return new WebSocket<String>() {
@SuppressWarnings("unchecked")
public void onReady(final WebSocket.In<String> in,
final WebSocket.Out<String> out) {
if (Cache.get("channels") == null) {
List<Out> outs = new ArrayList<Out>();
outs.add(out);
Cache.set("channels", outs);
} else ((List<Out>) Cache.get("channels")).add(out);
System.out.println("<" + Cache.get("channels"));
in.onClose(new F.Callback0() {
@Override
public void invoke() throws Throwable {
((List<Out>) Cache.get("channels")).remove(out);
out.close();
}
});
}
};
}
示例11: getSessionPrivileges
import play.cache.Cache; //导入方法依赖的package包/类
public static HashSet<String> getSessionPrivileges() throws DisconnectedUser {
String username = connected();
if (username == null) {
throw new DisconnectedUser("(No set)");
}
@SuppressWarnings("unchecked")
HashSet<String> privileges = Cache.get("user:" + username + ":privileges", HashSet.class);
if (privileges != null) {
Cache.set("user:" + username + ":privileges", privileges, MyDMAM.getPlayBootstrapper().getSessionTTL());
return privileges;
}
Session.current().clear();
throw new DisconnectedUser(username);
}
示例12: getAutoCompleteListForDataset
import play.cache.Cache; //导入方法依赖的package包/类
public static List<String> getAutoCompleteListForDataset()
{
//Logger.debug("Entering SearchDAO.java:getAutoCompleteListForDataset()");
List<String> cachedAutoCompleteListForDataset = (List<String>)Cache.get(SEARCH_AUTOCOMPLETE_LIST_DATASET);
if (cachedAutoCompleteListForDataset == null || cachedAutoCompleteListForDataset.size() == 0)
{
List<String> datasetList = getJdbcTemplate().queryForList(GET_DATASET_AUTO_COMPLETE_LIST, String.class);
cachedAutoCompleteListForDataset = datasetList.stream().collect(Collectors.toList());
Collections.sort(cachedAutoCompleteListForDataset);
Cache.set(SEARCH_AUTOCOMPLETE_LIST_DATASET, cachedAutoCompleteListForDataset, 60*60);
}
return cachedAutoCompleteListForDataset;
}
示例13: getCachedEvents
import play.cache.Cache; //导入方法依赖的package包/类
public static F.Promise<models.eventful.EventList> getCachedEvents(Location loc) {
// Build Caching-Key
String sKey = "events-"+loc.getLat()+loc.getLng();
@SuppressWarnings("unchecked")
// Is the result already in the Cache?
F.Promise<models.eventful.EventList> eventList = (Promise<models.eventful.EventList>) Cache.get(sKey);
// No? -> Retrieve it
if(eventList == null) eventList = EventfulAPI.search4Events(loc);
// Put it into the cache
Cache.set(sKey, eventList);
return eventList;
}
示例14: getSubordinatesAsString
import play.cache.Cache; //导入方法依赖的package包/类
/**
* Get the list of subordinates of an actor as a string.
*
* @param actorId
* the actor id
* @param separator
* the separator (data aggregate)
*/
public static String getSubordinatesAsString(Long actorId, String separator) {
String cacheKey = ACTOR_HIERARCHY_CACHE_PREFIX + "subordinates.asstring." + actorId + "." + separator;
String subordinatesString = (String) Cache.get(cacheKey);
if (subordinatesString != null) {
Logger.debug("actor hierarchy: '" + cacheKey + "' read from cache");
return subordinatesString;
}
Set<Long> subordinatesId = getSubordinatesAsId(actorId);
StringBuilder builder = new StringBuilder();
boolean firstLoop = true;
for (Long id : subordinatesId) {
if (!firstLoop) {
builder.append(separator);
}
builder.append(id.toString());
firstLoop = false;
}
subordinatesString = builder.toString();
// set the result in the cache
Cache.set(cacheKey, subordinatesString, CACHE_TTL);
return subordinatesString;
}
示例15: allocateUpdateAuthorization
import play.cache.Cache; //导入方法依赖的package包/类
/**
* Add update authorization for the specified list of attachments.
*
* @param allowedIds
* a list of ids
* @param uid
* the uid of the authorized user
*/
private static void allocateUpdateAuthorization(Set<Long> allowedIds, String uid) {
if (Cache.get(IFrameworkConstants.ATTACHMENT_WRITE_AUTHZ_CACHE_PREFIX + uid) != null) {
@SuppressWarnings("unchecked")
Set<Long> otherAllowerIds = (Set<Long>) Cache.get(IFrameworkConstants.ATTACHMENT_WRITE_AUTHZ_CACHE_PREFIX + uid);
allowedIds.addAll(otherAllowerIds);
}
Cache.set(IFrameworkConstants.ATTACHMENT_WRITE_AUTHZ_CACHE_PREFIX + uid, allowedIds, AUTHZ_FILE_DURATION);
}