diff options
| author | Bnyro <bnyro@tutanota.com> | 2026-07-15 18:05:21 +0200 |
|---|---|---|
| committer | Bnyro <bnyro@tutanota.com> | 2026-07-16 12:37:26 +0200 |
| commit | f2432e33d6e3778cb0e976d602bb259d60081d64 (patch) | |
| tree | ae375f5922beeba45d4feed3b6adef5566efdf84 /searx/cache.py | |
| parent | 7b2199ecdf75a00981583fa2f392a785dfc4fcee (diff) | |
[fix] engine cache: return default value when cache entry expired
It's possible that it's expired but has not yet been automatically deleted
by the periodic maintenance because that, by default, runs only every 2 hours.
Related:
- see https://github.com/searxng/searxng/pull/6409#discussion_r3584712601
Diffstat (limited to 'searx/cache.py')
| -rw-r--r-- | searx/cache.py | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/searx/cache.py b/searx/cache.py index e6b6541d9..1b2d50e2b 100644 --- a/searx/cache.py +++ b/searx/cache.py @@ -458,12 +458,22 @@ class ExpireCacheSQLite(sqlitedb.SQLiteAppl, ExpireCache): # Before values are taken from the table, a maintenance interval may # need to be carried out. self.maintenance() - sql = f"SELECT value FROM {table} WHERE key = ?" + sql = f"SELECT value, expire FROM {table} WHERE key = ?" row = self.DB.execute(sql, (key,)).fetchone() if row is None: return default - return self.deserialize(row[0]) + # Check if value is expired. It's possible that it's expired but has not + # yet been automatically deleted by the periodic maintenance + (value, expire) = row + now = time.time() + if expire < now: + # The record is deleted during the maintenance interval. Deleting + # the record at this point offers no advantage, as a SELECT + # statement must be executed for every cache.get request anyways. + return default + + return self.deserialize(value) def pairs(self, ctx: str) -> Iterator[tuple[str, typing.Any]]: """Iterate over key/value pairs from table given by argument ``ctx``. |
