.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
searx.favicons.cache.FaviconCacheMEM Class Reference
Inheritance diagram for searx.favicons.cache.FaviconCacheMEM:
Collaboration diagram for searx.favicons.cache.FaviconCacheMEM:

Public Member Functions

 __init__ (self, FaviconCacheConfig cfg)
None|tuple[bytes|None, str|None] __call__ (self, str resolver, str authority)
bool set (self, str resolver, str authority, str|None mime, bytes|None data)
 state (self)
 maintenance (self, bool force=False)
Public Member Functions inherited from searx.favicons.cache.FaviconCache
 __init__ (self, FaviconCacheConfig cfg)
None|tuple[None|bytes, None|str] __call__ (self, str resolver, str authority)

Public Attributes

 cfg = cfg

Protected Attributes

dict _data = {}
dict _sha_mime = {}

Detailed Description

Favicon cache in process' memory.  Its just a POC that stores the
favicons in the memory of the process.

.. attention::

   Don't use it in production, it will blow up your memory!!

Definition at line 447 of file cache.py.

Constructor & Destructor Documentation

◆ __init__()

searx.favicons.cache.FaviconCacheMEM.__init__ ( self,
FaviconCacheConfig cfg )

Definition at line 457 of file cache.py.

457 def __init__(self, cfg: FaviconCacheConfig):
458
459 self.cfg = cfg
460 self._data: dict[str, t.Any] = {}
461 self._sha_mime: dict[str, tuple[str, str | None]] = {}
462

Member Function Documentation

◆ __call__()

None | tuple[bytes | None, str | None] searx.favicons.cache.FaviconCacheMEM.__call__ ( self,
str resolver,
str authority )

Definition at line 463 of file cache.py.

463 def __call__(self, resolver: str, authority: str) -> None | tuple[bytes | None, str | None]:
464
465 sha, mime = self._sha_mime.get(f"{resolver}:{authority}", (None, None))
466 if sha is None:
467 return None
468 data = self._data.get(sha)
469 if data == FALLBACK_ICON:
470 data = None
471 return data, mime
472

References _data, and _sha_mime.

◆ maintenance()

searx.favicons.cache.FaviconCacheMEM.maintenance ( self,
bool force = False )
Performs maintenance on the cache

Reimplemented from searx.favicons.cache.FaviconCache.

Definition at line 495 of file cache.py.

495 def maintenance(self, force: bool = False):
496 pass

◆ set()

bool searx.favicons.cache.FaviconCacheMEM.set ( self,
str resolver,
str authority,
str | None mime,
bytes | None data )
Set data and mime-type in the cache.  If data is None, the
:py:obj:`FALLBACK_ICON` is registered. in the cache.

Reimplemented from searx.favicons.cache.FaviconCache.

Definition at line 473 of file cache.py.

473 def set(self, resolver: str, authority: str, mime: str | None, data: bytes | None) -> bool:
474
475 if data is None:
476 data = FALLBACK_ICON
477 mime = None
478
479 elif mime is None:
480 logger.error(
481 "favicon resolver %s tries to cache mime-type None for authority %s",
482 resolver,
483 authority,
484 )
485 return False
486
487 digest = hashlib.sha256(data).hexdigest()
488 self._data[digest] = data
489 self._sha_mime[f"{resolver}:{authority}"] = (digest, mime)
490 return True
491

References _data, and _sha_mime.

◆ state()

searx.favicons.cache.FaviconCacheMEM.state ( self)
Returns a :py:obj:`FaviconCacheStats` (key/values) with information
on the state of the cache.

Reimplemented from searx.favicons.cache.FaviconCache.

Definition at line 492 of file cache.py.

492 def state(self):
493 return FaviconCacheStats(favicons=len(self._data.keys()))
494

References _data.

Member Data Documentation

◆ _data

dict searx.favicons.cache.FaviconCacheMEM._data = {}
protected

Definition at line 460 of file cache.py.

Referenced by __call__(), set(), and state().

◆ _sha_mime

dict searx.favicons.cache.FaviconCacheMEM._sha_mime = {}
protected

Definition at line 461 of file cache.py.

Referenced by __call__(), and set().

◆ cfg

searx.favicons.cache.FaviconCacheMEM.cfg = cfg

Definition at line 459 of file cache.py.

Referenced by searx.cache.ExpireCache.secret_hash().


The documentation for this class was generated from the following file:
  • /home/andrew/Documents/code/public/searxng/searx/favicons/cache.py