.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
searx.favicons.cache Namespace Reference

Classes

class  FaviconCache
class  FaviconCacheConfig
class  FaviconCacheMEM
class  FaviconCacheNull
class  FaviconCacheSQLite
class  FaviconCacheStats

Functions

 state ()
 maintenance (bool force=True, bool debug=False)
 init ("FaviconCacheConfig" cfg)

Variables

str CACHE : "FaviconCache"
str FALLBACK_ICON = b"FALLBACK_ICON"
 logger = logger.getChild('favicons.cache')
 app = typer.Typer()

Detailed Description

Implementations for caching favicons.

:py:obj:`FaviconCacheConfig`:
  Configuration of the favicon cache

:py:obj:`FaviconCache`:
  Abstract base class for the implementation of a favicon cache.

:py:obj:`FaviconCacheSQLite`:
  Favicon cache that manages the favicon BLOBs in a SQLite DB.

:py:obj:`FaviconCacheNull`:
  Fallback solution if the configured cache cannot be used for system reasons.

----

Function Documentation

◆ init()

searx.favicons.cache.init ( "FaviconCacheConfig" cfg)
Initialization of a global ``CACHE``

Definition at line 72 of file cache.py.

72def init(cfg: "FaviconCacheConfig"):
73 """Initialization of a global ``CACHE``"""
74
75 global CACHE # pylint: disable=global-statement
76 if cfg.db_type == "sqlite":
77 if sqlite3.sqlite_version_info <= (3, 35):
78 logger.critical(
79 "Disable favicon caching completely: SQLite library (%s) is too old! (require >= 3.35)",
80 sqlite3.sqlite_version,
81 )
82 CACHE = FaviconCacheNull(cfg)
83 else:
84 CACHE = FaviconCacheSQLite(cfg)
85 elif cfg.db_type == "mem":
86 logger.error("Favicons are cached in memory, don't use this in production!")
87 CACHE = FaviconCacheMEM(cfg)
88 else:
89 raise NotImplementedError(f"favicons db_type '{cfg.db_type}' is unknown")
90
91
92@t.final

◆ maintenance()

searx.favicons.cache.maintenance ( bool force = True,
bool debug = False )
perform maintenance of the cache

Definition at line 52 of file cache.py.

52def maintenance(force: bool = True, debug: bool = False):
53 """perform maintenance of the cache"""
54 root_log = logging.getLogger()
55 if debug:
56 root_log.setLevel(logging.DEBUG)
57 else:
58 root_log.handlers = []
59 handler = logging.StreamHandler()
60 handler.setFormatter(logging.Formatter("%(message)s"))
61 logger.addHandler(handler)
62 logger.setLevel(logging.DEBUG)
63
64 state_t0 = CACHE.state()
65 CACHE.maintenance(force=force)
66 state_t1 = CACHE.state()
67 state_delta = state_t0 - state_t1
68 print("The cache has been reduced by:")
69 print(state_delta.report("\n- {descr}: {val}").lstrip("\n"))
70
71

◆ state()

searx.favicons.cache.state ( )
show state of the cache

Definition at line 46 of file cache.py.

46def state():
47 """show state of the cache"""
48 print(CACHE.state().report())
49
50
51@app.command()

Variable Documentation

◆ app

searx.favicons.cache.app = typer.Typer()

Definition at line 42 of file cache.py.

◆ CACHE

str searx.favicons.cache.CACHE : "FaviconCache"

Definition at line 38 of file cache.py.

◆ FALLBACK_ICON

str searx.favicons.cache.FALLBACK_ICON = b"FALLBACK_ICON"

Definition at line 39 of file cache.py.

◆ logger

searx.favicons.cache.logger = logger.getChild('favicons.cache')

Definition at line 41 of file cache.py.