Resource... contexts)
throws StoreException
{
StatementPattern pattern = new StatementPattern(subj, pred, obj, includeInferred, contexts);
CachedSize cached = cachedSizes.get(pattern);
StatementClient client = this.client.statements();
client.setLimit(1);
if (cached != null && (cached.isAbsent() || !cached.isSizeAvailable())) {
// Only calculate if cached value is old
client.ifNoneMatch(cached.getETag());
}
GraphResult result = client.get(subj, pred, obj, includeInferred, contexts);
int maxAge = client.getMaxAge();
if (result == null) {
assert cached != null : "Server did not return a size value";
cached.refreshed(now, maxAge);
}
else {
cached = new CachedSize(result.hasNext(), client.getETag());
cached.refreshed(now, maxAge);
cachedSizes.put(pattern, cached);
}
containsFreshValues |= maxAge > 0;
return cached.isAbsent();