@Test public void testExternalizeRenderResultPartial() throws IOException, ClassNotFoundException { RenderResultCache.setAltCache(new AltCacheSimpleImpl()); Map<String, String> map = new HashMap<String, String>(); map.put("a", "aa"); map.put("b", "bb"); StringBuilder sb = new StringBuilder("hello"); long rt = 1000; CacheableRunner cr = new CacheableRunner("1m", "anything") { @Override protected RenderResult render() { return null; } }; Map<Integer, ActionRunner> runners = new HashMap<Integer, ActionRunner>(); runners.put(2, cr); RenderResultPartial rr = new RenderResultPartial(map, sb, rt, runners); byte[] ba = write(rr); rr = (RenderResultPartial) read(ba); assertNotNull(rr); Map<String, String> headers = rr.getHeaders(); assertEquals(2, headers.size()); assertEquals("aa", headers.get("a")); assertEquals("hello", rr.getText()); assertEquals(rt, rr.renderTime); Map<Integer, ActionRunner> map2 = rr.getActionRunners(); assertEquals(1, map2.size()); }
/** * @param keyBase usually the fully qualified method name of the controller action * @param objs * @return */ protected static RenderResult getFromCache(String keyBase, Object... objs) { // the key building with caller info and the arguments if (RenderResultCache.shouldIgnoreCache()) return null; String caller = buildKey(keyBase, objs); Object object = Cache.get(caller); if (object instanceof RenderResult) { return (RenderResult) object; } else { return null; } }
/** * set a flag to instruct the cache runner to bypass cache checking for reading but still cache * the result, for the current response and next request */ public static void ignoreCacheNowAndNext() { RenderResultCache.setIgnoreCacheInCurrentAndNextReq(true); }
/** * set a flag to instruct the cache runner to bypass cache checking for reading but still cache * the result */ public static void ignoreCache() { RenderResultCache.setIgnoreCache(true); }