RequestServer: Add a time parameter to the clear cache endpoint

This allows removing cache entries last accessed since a provided
timestamp.
This commit is contained in:
Timothy Flynn 2025-11-02 16:44:30 -05:00 committed by Tim Flynn
parent ba49942b6d
commit 3f61f0f189
Notes: github-actions[bot] 2025-11-12 14:08:53 +00:00
11 changed files with 35 additions and 38 deletions

View file

@ -97,7 +97,7 @@ ErrorOr<CacheIndex> CacheIndex::create(Database::Database& database)
Statements statements {};
statements.insert_entry = TRY(database.prepare_statement("INSERT OR REPLACE INTO CacheIndex VALUES (?, ?, ?, ?, ?, ?, ?);"sv));
statements.remove_entry = TRY(database.prepare_statement("DELETE FROM CacheIndex WHERE cache_key = ?;"sv));
statements.remove_all_entries = TRY(database.prepare_statement("DELETE FROM CacheIndex;"sv));
statements.remove_entries_accessed_since = TRY(database.prepare_statement("DELETE FROM CacheIndex WHERE last_access_time >= ? RETURNING cache_key;"sv));
statements.select_entry = TRY(database.prepare_statement("SELECT * FROM CacheIndex WHERE cache_key = ?;"sv));
statements.update_response_headers = TRY(database.prepare_statement("UPDATE CacheIndex SET response_headers = ? WHERE cache_key = ?;"sv));
statements.update_last_access_time = TRY(database.prepare_statement("UPDATE CacheIndex SET last_access_time = ? WHERE cache_key = ?;"sv));
@ -136,10 +136,17 @@ void CacheIndex::remove_entry(u64 cache_key)
m_entries.remove(cache_key);
}
void CacheIndex::remove_all_entries()
void CacheIndex::remove_entries_accessed_since(UnixDateTime since, Function<void(u64 cache_key)> on_entry_removed)
{
m_database.execute_statement(m_statements.remove_all_entries, {});
m_entries.clear();
m_database.execute_statement(
m_statements.remove_entries_accessed_since,
[&](auto statement_id) {
auto cache_key = m_database.result_column<u64>(statement_id, 0);
m_entries.remove(cache_key);
on_entry_removed(cache_key);
},
since);
}
void CacheIndex::update_response_headers(u64 cache_key, HTTP::HeaderMap response_headers)