0
我試圖禁用緩存在HsqlDB 2.3.4中的TEXT表,以便針對CSV文件的查詢返回最新值,而不是從hsqdb內存緩存值。禁用TEXT表的緩存
設置cache_rows=0
引發IllegalArgumentException,並將其設置爲1似乎不起作用。 cached_rows
設置可能會重置爲默認值(10000行)或最小值(100行)。
如果不支持禁用緩存,是否可以在查詢運行之前刪除給定的表緩存或甚至是數據庫緩存?看來關閉數據庫或刪除整個模式是受支持的,但這不是我想要實現的解決方法。
EDIT 1.示例代碼
public static void main(String[] args) throws Exception {
String dir = args[0];
Class.forName("org.hsqldb.jdbc.JDBCDriver");
Connection conn = DriverManager.getConnection("jdbc:hsqldb:file:" + dir + "");
{
Statement st = conn.createStatement();
st.execute("DROP TABLE books IF EXISTS");
st.close();
}
{
Statement st = conn.createStatement();
st.execute("CREATE TEXT TABLE books (Title varchar(64), Author varchar(64))");
st.close();
}
{
Statement st = conn.createStatement();
st.execute("SET TABLE books SOURCE \"books.csv;ignore_first=true;cache_rows=1\"");
st.close();
}
for (int x = 0; x < 3; x++) {
System.out.println("iteration: " + x);
Statement st = conn.createStatement();
ResultSet rs = st.executeQuery("SELECT * FROM books");
while (rs.next()) {
System.out.println(rs.getString(1) + " : " + rs.getString(2));
}
st.close();
Thread.sleep(15000L);
//data from files is cached, results shows original rows
//even after the file was modified on the file system
//need to execute source off/on to reload the data from files
}
conn.close();
}
是的,設置SOURCE OFF/ON可以重新加載文件中的數據。沒有這些命令,即使文件被修改,結果集也會保持返回原始值。 –