diff --git a/sqlitecluster/SQLite.cpp b/sqlitecluster/SQLite.cpp index 23e13c767..2dd5a0891 100644 --- a/sqlitecluster/SQLite.cpp +++ b/sqlitecluster/SQLite.cpp @@ -511,7 +511,7 @@ bool SQLite::read(const string& query, SQResult& result, bool skipInfoWarn) cons } else { _isDeterministicQuery = true; queryResult = !SQuery(_db, "read only query", query, result, 2000 * STIME_US_PER_MS, skipInfoWarn); - if (_isDeterministicQuery && queryResult) { + if (_isDeterministicQuery && queryResult && insideTransaction()) { _queryCache.emplace(make_pair(query, result)); } } diff --git a/sqlitecluster/SQLite.h b/sqlitecluster/SQLite.h index f5ddbc814..602ebf213 100644 --- a/sqlitecluster/SQLite.h +++ b/sqlitecluster/SQLite.h @@ -216,7 +216,7 @@ class SQLite { const string getMostRecentSQLiteErrorLog() const; // Returns true if we're inside an uncommitted transaction. - bool insideTransaction() { return _insideTransaction; } + bool insideTransaction() const { return _insideTransaction; } // Looks up the exact SQL of a paricular commit to the database, as well as gets the SHA1 hash of the database // immediately following tha commit.