Browse Source

Updating the cache on cache miss

pull/137/head
gauravgupta 9 years ago
parent
commit
eebfd8bbda
  1. 13
      json-path/src/main/java/com/jayway/jsonpath/internal/JsonReader.java

13
json-path/src/main/java/com/jayway/jsonpath/internal/JsonReader.java

@ -23,6 +23,8 @@ import com.jayway.jsonpath.ParseContext;
import com.jayway.jsonpath.Predicate; import com.jayway.jsonpath.Predicate;
import com.jayway.jsonpath.ReadContext; import com.jayway.jsonpath.ReadContext;
import com.jayway.jsonpath.TypeRef; import com.jayway.jsonpath.TypeRef;
import com.jayway.jsonpath.spi.cache.CacheProvider;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -132,11 +134,14 @@ public class JsonReader implements ParseContext, DocumentContext {
@Override @Override
public <T> T read(String path, Predicate... filters) { public <T> T read(String path, Predicate... filters) {
notEmpty(path, "path can not be null or empty"); notEmpty(path, "path can not be null or empty");
JsonPath cached = configuration.CacheProvider().get(path); CacheProvider cache = configuration.CacheProvider();
if(cached != null){ JsonPath jsonPath = cache.get(path);
return read(cached); if(jsonPath != null){
return read(jsonPath);
}else { }else {
return read(compile(path, filters)); jsonPath = compile(path, filters);
cache.put(path, jsonPath);
return read(jsonPath);
} }
} }

Loading…
Cancel
Save