@Override public List<T> then(Task<JSONObject> task) throws Exception { JSONObject json = task.getResult(); // Cache the results, unless we are ignoring the cache ParseQuery.CachePolicy policy = state.cachePolicy(); if (policy != null && (policy != ParseQuery.CachePolicy.IGNORE_CACHE)) { ParseKeyValueCache.saveToKeyValueCache(command.getCacheKey(), json.toString()); } long queryReceived = System.nanoTime(); List<T> response = convertFindResponse(state, task.getResult()); long objectsParsed = System.nanoTime(); if (json.has("trace")) { Object serverTrace = json.get("trace"); PLog.d("ParseQuery", String.format("Query pre-processing took %f seconds\n" + "%s\n" + "Client side parsing took %f seconds\n", (querySent - queryStart) / (1000.0f * 1000.0f), serverTrace, (objectsParsed - queryReceived) / (1000.0f * 1000.0f))); } return response; } }, Task.BACKGROUND_EXECUTOR);
@Test public void testGetCacheKey() throws Exception { // Make test command String httpPath = "www.parse.com"; JSONObject jsonParameters = new JSONObject() .put("count", 1) .put("limit", 1); String sessionToken = "sessionToken"; String localId = "localId"; ParseRESTCommand command = new ParseRESTCommand.Builder() .httpPath(httpPath) .jsonParameters(jsonParameters) .method(ParseHttpRequest.Method.POST) .sessionToken(sessionToken) .localId(localId) .build(); String cacheKey = command.getCacheKey(); assertTrue(cacheKey.contains("ParseRESTCommand")); assertTrue(cacheKey.contains(ParseHttpRequest.Method.POST.toString())); assertTrue(cacheKey.contains(ParseDigestUtils.md5(httpPath))); String str = ParseDigestUtils.md5(ParseRESTCommand.toDeterministicString(jsonParameters) + sessionToken); assertTrue(cacheKey.contains(str)); }
@Test public void testGetCacheKeyWithNoJSONParameters() { // Make test command String httpPath = "www.parse.com"; String sessionToken = "sessionToken"; String localId = "localId"; ParseRESTCommand command = new ParseRESTCommand.Builder() .httpPath(httpPath) .method(ParseHttpRequest.Method.POST) .sessionToken(sessionToken) .localId(localId) .build(); String cacheKey = command.getCacheKey(); assertTrue(cacheKey.contains("ParseRESTCommand")); assertTrue(cacheKey.contains(ParseHttpRequest.Method.POST.toString())); assertTrue(cacheKey.contains(ParseDigestUtils.md5(httpPath))); assertTrue(cacheKey.contains(ParseDigestUtils.md5(sessionToken))); }