@Override public Object get(Object key) { // Check for null as Cache should not store null values / keys if (key == null) { throw new NullPointerException("key is null"); } CacheValue cacheValue = map.get(key); // Check for null if (cacheValue == null) { return null; } // Check if to be autoexpired, autoExpireTimeInMs = 0 means expire immediately / no caching // Note: This point will never be reached if the value was put in cache when autoExpireTimeInMs was 0 if (this.autoExpireTimeInMs >= 0) { // Check if expired long now = new Date().getTime(); if (cacheValue.getLastUpateTime() + this.autoExpireTimeInMs < now) { // Expired, remove remove(key); return null; } } // Not expired, return the value return cacheValue.getValue(); }
@Override public Object get(Object key) { // Check for null as Cache should not store null values / keys if (key == null) { throw new NullPointerException("key is null"); } CacheValue cacheValue = map.get(key); // Check for null if (cacheValue == null) { return null; } // Check if to be autoexpired, autoExpireTimeInMs = 0 means expire immediately / no caching // Note: This point will never be reached if the value was put in cache when autoExpireTimeInMs was 0 if (this.autoExpireTimeInMs >= 0) { // Check if expired long now = new Date().getTime(); if (cacheValue.getLastUpdateTime() + this.autoExpireTimeInMs < now) { // Expired, remove remove(key); return null; } } // Not expired, return the value return cacheValue.getValue(); }
@Override public void onFailure(Throwable caught) { // Call postfetch with null result postfetch(action, null); resultCallback.onFailure(caught); // Callback onFailure ArrayList<CallbackDispatchRequest<R>> pendingRequestCallbacks = pendingRequestCallbackMap .remove(action); for (CallbackDispatchRequest<R> pendingRequestCallback : pendingRequestCallbacks) { if (pendingRequestCallback.isPending()) { pendingRequestCallback.onFailure(caught); } } }
@Override public void put(Object key, Object value) { // No point caching if autoExpireTimeInMs = 0 if (this.autoExpireTimeInMs != 0) { // Check for null as Cache should not store null values / keys if (key == null) { throw new NullPointerException("key is null"); } if (value == null) { throw new NullPointerException("value is null"); } // Put in map map.put(key, new CacheValue(value)); } }
R prefetchResult = prefetch(action); if (prefetchResult != null) {
@Override public long getLastUpateTime(Object key) { // Check for null as Cache should not store null values / keys if (key == null) { throw new NullPointerException("key is null"); } CacheValue value = map.get(key); if (value != null) { return value.getLastUpdateTime(); } else { return -1; } }
@Override public long getLastUpateTime(Object key) { // Check for null as Cache should not store null values / keys if (key == null) { throw new NullPointerException("key is null"); } CacheValue value = map.get(key); // Check for null if (value != null) { return value.getLastUpateTime(); } else { return -1; } }
@Override public void onFailure(Throwable caught) { // Call postfetch with null result postfetch(action, null); resultCallback.onFailure(caught); // Callback onFailure List<CallbackDispatchRequest<R>> pendingRequestCallbacks = pendingRequestCallbackMap.remove(action); for (CallbackDispatchRequest<R> pendingRequestCallback : pendingRequestCallbacks) { if (pendingRequestCallback.isPending()) { pendingRequestCallback.onFailure(caught); } } }
@Override public void put(Object key, Object value) { // No point caching if autoExpireTimeInMs = 0 if (this.autoExpireTimeInMs != 0) { // Check for null as Cache should not store null values / keys if (key == null) { throw new NullPointerException("key is null"); } if (value == null) { throw new NullPointerException("value is null"); } // Put in map map.put(key, new CacheValue(value)); } }
R prefetchResult = prefetch(action); if (prefetchResult != null) {
@Override public void onSuccess(R result) { // Postfetch postfetch(action, result); resultCallback.onSuccess(result); // Callback onSuccess ArrayList<CallbackDispatchRequest<R>> pendingRequestCallbacks = pendingRequestCallbackMap .remove(action); for (CallbackDispatchRequest<R> pendingRequestCallback : pendingRequestCallbacks) { if (pendingRequestCallback.isPending()) { pendingRequestCallback.onSuccess(result); } } } });
@Override public void onSuccess(R result) { // Postfetch postfetch(action, result); resultCallback.onSuccess(result); // Callback onSuccess List<CallbackDispatchRequest<R>> pendingRequestCallbacks = pendingRequestCallbackMap.remove(action); for (CallbackDispatchRequest<R> pendingRequestCallback : pendingRequestCallbacks) { if (pendingRequestCallback.isPending()) { pendingRequestCallback.onSuccess(result); } } } });