in firestore/android/FirestoreSnippetsCpp/app/src/main/cpp/snippets.cpp [510:544]
void ReadDataSourceOptions(firebase::firestore::Firestore* db) {
using firebase::Future;
using firebase::firestore::DocumentReference;
using firebase::firestore::DocumentSnapshot;
using firebase::firestore::Error;
using firebase::firestore::FieldValue;
using firebase::firestore::Source;
// You can set the source option to control how a get call uses the offline
// cache.
//
// By default, a get call will attempt to fetch the latest document snapshot
// from your database. On platforms with offline support, the client library
// will use the offline cache if the network is unavailable or if the request
// times out.
//
// You can specify the source option in a Get() call to change the default
// behavior. You can fetch from only the database and ignore the offline
// cache, or you can fetch from only the offline cache. For example:
// [START get_document_options]
DocumentReference doc_ref = db->Collection("cities").Document("SF");
Source source = Source::kCache;
doc_ref.Get(source).OnCompletion([](const Future<DocumentSnapshot>& future) {
if (future.error() == Error::kErrorOk) {
const DocumentSnapshot& document = *future.result();
if (document.exists()) {
std::cout << "Cached document id: " << document.id() << std::endl;
} else {
}
} else {
std::cout << "Cached get failed: " << future.error_message() << std::endl;
}
});
// [END get_document_options]
}