.oO SearXNG Developer Documentation Oo.
|
Public Member Functions | |
bool | set (self, str key, typing.Any value, int|None expire, str|None ctx=None) |
typing.Any | get (self, str key, default=None, str|None ctx=None) |
bool | maintenance (self, bool force=False, bool truncate=False) |
ExpireCacheStats | state (self) |
bytes | serialize (self, typing.Any value) |
typing.Any | deserialize (self, bytes value) |
str | secret_hash (self, str|bytes name) |
Static Public Member Functions | |
ExpireCache | build_cache (ExpireCacheCfg cfg) |
str | normalize_name (str name) |
Static Public Attributes | |
ExpireCacheCfg | hash_token = "hash_token" |
Abstract base class for the implementation of a key/value cache with expire date.
|
static |
Factory to build a caching instance. .. note:: Currently, only the SQLite adapter is available, but other database types could be implemented in the future, e.g. a Valkey (Redis) adapter.
Definition at line 173 of file cache.py.
typing.Any searx.cache.ExpireCache.deserialize | ( | self, | |
bytes | value ) |
Definition at line 196 of file cache.py.
Referenced by searx.cache.ExpireCacheSQLite.get(), searx.cache.ExpireCacheSQLite.pairs(), and searx.cache.ExpireCacheSQLite.state().
typing.Any searx.cache.ExpireCache.get | ( | self, | |
str | key, | ||
default = None, | |||
str | None | ctx = None ) |
Return *value* of *key*. If key is unset, ``None`` is returned.
Reimplemented in searx.cache.ExpireCacheSQLite.
Definition at line 151 of file cache.py.
Referenced by searx.result_types._base.LegacyResult.__init__(), searx.result_types._base.LegacyResult.defaults_from(), and searx.answerers._core.AnswerStorage.register().
bool searx.cache.ExpireCache.maintenance | ( | self, | |
bool | force = False, | ||
bool | truncate = False ) |
Performs maintenance on the cache. ``force``: Maintenance should be carried out even if the maintenance interval has not yet been reached. ``truncate``: Truncate the entire cache, which is necessary, for example, if the password has changed.
Reimplemented in searx.cache.ExpireCacheSQLite.
Definition at line 155 of file cache.py.
Referenced by searx.cache.ExpireCacheSQLite.get(), searx.cache.ExpireCacheSQLite.init(), searx.cache.ExpireCacheSQLite.pairs(), searx.cache.ExpireCacheSQLite.set(), and searx.favicons.cache.FaviconCacheSQLite.set().
|
static |
Returns a normalized name that can be used as a file name or as a SQL table name (is used, for example, to normalize the context name).
Definition at line 185 of file cache.py.
Referenced by searx.cache.ExpireCacheSQLite.get(), searx.cache.ExpireCacheSQLite.pairs(), and searx.cache.ExpireCacheSQLite.set().
str searx.cache.ExpireCache.secret_hash | ( | self, | |
str | bytes | name ) |
Creates a hash of the argument ``name``. The hash value is formed from the ``name`` combined with the :py:obj:`password <ExpireCacheCfg.password>`. Can be used, for example, to make the ``key`` stored in the DB unreadable for third parties.
Definition at line 200 of file cache.py.
References searx.botdetection.config.Config.cfg, searx.cache.ExpireCacheSQLite.cfg, searx.favicons.cache.FaviconCacheMEM.cfg, and searx.favicons.cache.FaviconCacheSQLite.cfg.
bytes searx.cache.ExpireCache.serialize | ( | self, | |
typing.Any | value ) |
Definition at line 192 of file cache.py.
Referenced by searx.cache.ExpireCacheSQLite.set().
bool searx.cache.ExpireCache.set | ( | self, | |
str | key, | ||
typing.Any | value, | ||
int | None | expire, | ||
str | None | ctx = None ) |
Set *key* to *value*. To set a timeout on key use argument ``expire`` (in sec.). If expire is unset the default is taken from :py:obj:`ExpireCacheCfg.MAXHOLD_TIME`. After the timeout has expired, the key will automatically be deleted. The ``ctx`` argument specifies the context of the ``key``. A key is only unique in its context. The concrete implementations of this abstraction determine how the context is mapped in the connected database. In SQL databases, for example, the context is a DB table or in a Key/Value DB it could be a prefix for the key. If the context is not specified (the default is ``None``) then a default context should be used, e.g. a default table for SQL databases or a default prefix in a Key/Value DB.
Reimplemented in searx.cache.ExpireCacheSQLite.
Definition at line 131 of file cache.py.
ExpireCacheStats searx.cache.ExpireCache.state | ( | self | ) |
Returns a :py:obj:`ExpireCacheStats`, which provides information about the status of the cache.
Reimplemented in searx.cache.ExpireCacheSQLite.
Definition at line 168 of file cache.py.
|
static |
Definition at line 128 of file cache.py.
Referenced by searx.cache.ExpireCacheSQLite.init().