@Override public Integer call() throws Exception { JSONObject cached = ParseKeyValueCache.jsonFromKeyValueCache(cacheKey, state.maxCacheAge()); if (cached == null) { throw new ParseException(ParseException.CACHE_MISS, "results not cached"); } try { return cached.getInt("count"); } catch (JSONException e) { throw new ParseException(ParseException.CACHE_MISS, "the cache contains corrupted json"); } } }, Task.BACKGROUND_EXECUTOR);
public Builder(State state) { className = state.className(); where.putAll(state.constraints()); includes.addAll(state.includes()); selectedKeys = state.selectedKeys() != null ? new HashSet(state.selectedKeys()) : null; limit = state.limit(); skip = state.skip(); order.addAll(state.order()); extraOptions.putAll(state.extraOptions()); trace = state.isTracingEnabled(); cachePolicy = state.cachePolicy(); maxCacheAge = state.maxCacheAge(); isFromLocalDatastore = state.isFromLocalDatastore(); pinName = state.pinName(); ignoreACLs = state.ignoreACLs(); }
@Test public void testDefaults() { ParseQuery.State.Builder<ParseObject> builder = new ParseQuery.State.Builder<>("TestObject"); ParseQuery.State<ParseObject> state = builder.build(); assertEquals("TestObject", state.className()); assertTrue(state.constraints().isEmpty()); assertTrue(state.includes().isEmpty()); assertNull(state.selectedKeys()); assertEquals(-1, state.limit()); assertEquals(0, state.skip()); assertTrue(state.order().isEmpty()); assertTrue(state.extraOptions().isEmpty()); assertFalse(state.isTracingEnabled()); assertEquals(ParseQuery.CachePolicy.IGNORE_CACHE, state.cachePolicy()); assertEquals(Long.MAX_VALUE, state.maxCacheAge()); assertFalse(state.isFromLocalDatastore()); assertNull(state.pinName()); assertFalse(state.ignoreACLs()); }
/** * Returns whether or not this query has a cached result. */ //TODO (grantland): should be done Async since it does disk i/o & calls through to current user public boolean hasCachedResult() { throwIfLDSEnabled(); // TODO(grantland): Is there a more efficient way to accomplish this rather than building a // new state just to check it's cacheKey? State<T> state = builder.build(); ParseUser user = null; try { user = ParseTaskUtils.wait(getUserAsync(state)); } catch (ParseException e) { // do nothing } String sessionToken = user != null ? user.getSessionToken() : null; /* * TODO: Once the count queries are cached, only return false when both queries miss in the * cache. */ String raw = ParseKeyValueCache.loadFromKeyValueCache( ParseRESTQueryCommand.findCommand(state, sessionToken).getCacheKey(), state.maxCacheAge() ); return raw != null; }
@Override public List<T> call() throws Exception { JSONObject cached = ParseKeyValueCache.jsonFromKeyValueCache(cacheKey, state.maxCacheAge()); if (cached == null) { throw new ParseException(ParseException.CACHE_MISS, "results not cached"); } try { return networkController.convertFindResponse(state, cached); } catch (JSONException e) { throw new ParseException(ParseException.CACHE_MISS, "the cache contains corrupted json"); } } }, Task.BACKGROUND_EXECUTOR);