Search in sources :

Example 1 with Cache

use of com.jayway.jsonpath.spi.cache.Cache in project JsonPath by jayway.

the class JsonContext method read.

@Override
public <T> T read(String path, Predicate... filters) {
    notEmpty(path, "path can not be null or empty");
    Cache cache = CacheProvider.getCache();
    path = path.trim();
    LinkedList filterStack = new LinkedList<Predicate>(asList(filters));
    String cacheKey = Utils.concat(path, filterStack.toString());
    JsonPath jsonPath = cache.get(cacheKey);
    if (jsonPath != null) {
        return read(jsonPath);
    } else {
        jsonPath = compile(path, filters);
        cache.put(cacheKey, jsonPath);
        return read(jsonPath);
    }
}
Also used : JsonPath(com.jayway.jsonpath.JsonPath) LinkedList(java.util.LinkedList) Cache(com.jayway.jsonpath.spi.cache.Cache)

Aggregations

JsonPath (com.jayway.jsonpath.JsonPath)1 Cache (com.jayway.jsonpath.spi.cache.Cache)1 LinkedList (java.util.LinkedList)1