diff options
Diffstat (limited to 'searx/cache.py')
| -rw-r--r-- | searx/cache.py | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/searx/cache.py b/searx/cache.py index 7ba5c8886..16386838f 100644 --- a/searx/cache.py +++ b/searx/cache.py @@ -10,6 +10,7 @@ from __future__ import annotations __all__ = ["ExpireCacheCfg", "ExpireCacheStats", "ExpireCache", "ExpireCacheSQLite"] import abc +from collections.abc import Iterator import dataclasses import datetime import hashlib @@ -396,6 +397,20 @@ class ExpireCacheSQLite(sqlitedb.SQLiteAppl, ExpireCache): return self.deserialize(row[0]) + def pairs(self, ctx: str) -> Iterator[tuple[str, typing.Any]]: + """Iterate over key/value pairs from table given by argument ``ctx``. + If ``ctx`` argument is ``None`` (the default), a table name is + generated from the :py:obj:`ExpireCacheCfg.name`.""" + table = ctx + self.maintenance() + + if not table: + table = self.normalize_name(self.cfg.name) + + if table in self.table_names: + for row in self.DB.execute(f"SELECT key, value FROM {table}"): + yield row[0], self.deserialize(row[1]) + def state(self) -> ExpireCacheStats: cached_items = {} for table in self.table_names: |