.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 73 of file cache.py.

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

◆ maintenance()

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

Definition at line 53 of file cache.py.

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

◆ state()

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

Definition at line 47 of file cache.py.

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

Variable Documentation

◆ app

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

Definition at line 43 of file cache.py.

◆ CACHE

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

Definition at line 39 of file cache.py.

◆ FALLBACK_ICON

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

Definition at line 40 of file cache.py.

◆ logger

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

Definition at line 42 of file cache.py.