public static void _cache(Map<?, ?> args, Closure body, PrintWriter out, ExecutableTemplate template, int fromLine) { String key = args.get("arg").toString(); String duration = null; if (args.containsKey("for")) { duration = args.get("for").toString(); } Object cached = Cache.get(key); if (cached != null) { out.print(cached); return; } String result = JavaExtensions.toString(body); Cache.set(key, result, duration); out.print(result); }
@Override public void remove(String key) { Cache.remove(key); } }
/** * Add an element only if it doesn't exist and store it indefinitely. * @param key Element key * @param value Element value */ public static void add(String key, Object value) { checkSerializable(value); cacheImpl.add(key, value, Time.parseDuration(null)); }
@Override public void put(String key, String value, int expirationMillis) { Cache.set(key, value, expirationMillis / 1000); }
@Override public String get(String key) { Object value = Cache.get(key); return value == null ? null : value.toString(); }
public void destroySession(WebContext context) { final PlayWebContext webContext = (PlayWebContext) context; final String logoutRequest = context.getRequestParameter("logoutRequest"); logger.debug("logoutRequest: {}", logoutRequest); final String ticket = StringUtils.substringBetween(logoutRequest, "SessionIndex>", "</"); logger.debug("extract ticket: {}", ticket); final String sessionId = (String) Cache.get(ticket); Cache.remove(ticket); webContext.getJavaSession().put(Pac4jConstants.SESSION_ID, sessionId); final ProfileManager profileManager = new ProfileManager(webContext); profileManager.remove(true); }
protected void _addToCache() { if (!_cacheEnabled()) return; String cacheKey = _cacheKey(); String expiration = _cacheExpiration(); play.cache.Cache.add(cacheKey, this, expiration); }
Cache.clear(); if (HotswapAgent.enabled) { try {
public void recordSession(WebContext context, String ticket) { logger.debug("ticket: {}", ticket); final PlayWebContext webContext = (PlayWebContext) context; final PlayCacheStore playCacheStore = (PlayCacheStore) webContext.getSessionStore(); final String sessionId = playCacheStore.getOrCreateSessionId(webContext); logger.debug("save sessionId: {}", sessionId); Cache.set(ticket, sessionId, playCacheStore.getProfileTimeout()); } }
/** * {@inheritDoc} */ public Object get(final WebContext context, final String key) { final String sessionId = getOrCreateSessionId(context); return Cache.get(getKey(sessionId, key)); }
public Result call(Context ctx) { try { String key = configuration.key(); Integer duration = configuration.duration(); Result result = (Result)Cache.get(key); if(result == null) { result = delegate.call(ctx); Cache.set(key, result, duration); } return result; } catch(RuntimeException e) { throw e; } catch(Throwable t) { throw new RuntimeException(t); } }
/** * {@inheritDoc} */ public void set(final WebContext context, final String key, final Object value) { int timeout; if (value instanceof UserProfile) { timeout = profileTimeout; } else { timeout = sessionTimeout; } final String sessionId = getOrCreateSessionId(context); Cache.set(getKey(sessionId, key), value, timeout); }
@Override public ISObject get(final String key) { ISObject sobj = Cache.get(key, ISObject.class); if (null != sobj) { return sobj;
/** * Add an element only if it doesn't exist. * @param key Element key * @param value Element value * @param expiration Ex: 10s, 3mn, 8h */ public static void add(String key, Object value, String expiration) { checkSerializable(value); cacheImpl.add(key, value, Time.parseDuration(expiration)); }
protected static <T extends Model> T findById(Class<T> cls, Object id, boolean useFactory, boolean useCache, String expiration) { T e = null; String k = null; if (useCache) { k = cacheKey(cls, id); e = play.cache.Cache.get(k, cls); } if (null == e) { if (useFactory) { e = (T)MorphiaPlugin.MorphiaModelLoader.getFactory(cls).findById(id); } else { e = q(cls).filter("_id", processId_(id)).get(); } } if (useCache && null != e) { play.cache.Cache.set(k, e, expiration); } return e; }
/** * Retrieve a value from the cache, or set it from a default Callable function. * * @param key Item key. * @param value to set if key does not exist * @param expiration expiration period in seconds. * @return value */ @SuppressWarnings("unchecked") public static <T> T getOrElse(String key, Callable<T> block, int expiration) throws Exception{ Object r = play.libs.Scala.orNull(play.api.cache.Cache.get(key,play.api.Play.unsafeApplication())); if (r == null) { T value = block.call(); set(key,value,expiration); return value; } else return (T)r; }
@Override public ISObject forceGet(final String key) { ISObject sobj = Cache.get(key, ISObject.class); if (null != sobj) { return sobj; } if (migrateData) { // try gfs first sobj = gs.get(key); if (null != sobj) { putLater(key, sobj, ss, new _.F0<Void>() { @Override public Void apply() { removeLater(key, gs, 60); return null; } }, _.F1); } } if (null == sobj) { sobj = ss.forceGet(key); if (!sobj.isValid()) { Throwable cause = sobj.getException(); Logger.warn(cause, "error load blob by key[%s]", key); } } return sobj; }
/** * Add an element only if it doesn't exist, and return only when * the element is effectively cached. * @param key Element key * @param value Element value * @param expiration Ex: 10s, 3mn, 8h * @return If the element an eventually been cached */ public static boolean safeAdd(String key, Object value, String expiration) { checkSerializable(value); return cacheImpl.safeAdd(key, value, Time.parseDuration(expiration)); }
public String getUrl() { if (!exists()) { if (null == tmpId) { tmpId = new ObjectId().toString() + TMP_ID_SUFFIX; } Cache.set(tmpId, this, "10min"); Map<String, Object> params = C.newMap("key", tmpId); return Router.getFullUrl("controllers.BlobController.view", params); } else { String key = getKey(); if (Cache.get(key) != null) { Map<String, Object> params = C.newMap("key", key); return Router.getFullUrl("controllers.BlobController.view", params); } else { return ss.getUrl(this); } } } }
@Override public void put(final String key, final ISObject sobj) throws UnexpectedIOException { if (putAsync) { putLater(key, sobj, ss, _.F0, new _.F1<Throwable, Void>() { @Override public Void apply(Throwable e) { Logger.warn(e, "error put storage object with key[%s]. persist into GridFS", key); gs.put(key, sobj); return null; } }); long len = sobj.getLength(); // suppose the network transfer 100K per second String timeout = (5 + len / (1000 * 100)) + "s"; Cache.set(key, sobj, timeout); } else { ss.put(key, sobj); } }