/** * If there is any documents in the cache matching the query, those are * returned, otherwise a direct call is made to the underlying reader. * * As such, this may return 1 document (if one is found in the cache) even * though there are thousands of documents in the underlying database that * match. */ @Override public List<DatabaseDocument<T>> getDocuments(DatabaseQuery<T> q, int limit) { List<DatabaseDocument<T>> docs = new ArrayList<DatabaseDocument<T>>(); docs.addAll(cache.getDocument(q, limit)); if (docs.size() == 0) { docs = reader.getDocuments(q, limit); cache.add(docs); } return docs; }
@Override public DatabaseDocument<T> getDocument(DatabaseQuery<T> q) { DatabaseDocument<T> doc = cache.getDocument(q); if (doc == null) { doc = reader.getDocument(q); cache.add(doc); } return getCopy(doc); }