.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, 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, force=False)
 
- Public Member Functions inherited from searx.favicons.cache.FaviconCache

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

Constructor & Destructor Documentation

◆ __init__()

searx.favicons.cache.FaviconCacheMEM.__init__ ( self,
cfg )
An instance of the favicon cache is build up from the configuration.

Reimplemented from searx.favicons.cache.FaviconCache.

Definition at line 437 of file cache.py.

437 def __init__(self, cfg):
438
439 self.cfg = cfg
440 self._data = {}
441 self._sha_mime = {}
442

Member Function Documentation

◆ __call__()

None | tuple[bytes | None, str | None] searx.favicons.cache.FaviconCacheMEM.__call__ ( self,
str resolver,
str authority )
Returns ``None`` or the tuple of ``(data, mime)`` that has been
registered in the cache.  The ``None`` indicates that there was no entry
in the cache.

Reimplemented from searx.favicons.cache.FaviconCache.

Definition at line 443 of file cache.py.

443 def __call__(self, resolver: str, authority: str) -> None | tuple[bytes | None, str | None]:
444
445 sha, mime = self._sha_mime.get(f"{resolver}:{authority}", (None, None))
446 if sha is None:
447 return None
448 data = self._data.get(sha)
449 if data == FALLBACK_ICON:
450 data = None
451 return data, mime
452

References searx.favicons.cache.FaviconCacheMEM._data, and searx.favicons.cache.FaviconCacheMEM._sha_mime.

◆ maintenance()

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

Reimplemented from searx.favicons.cache.FaviconCache.

Definition at line 475 of file cache.py.

475 def maintenance(self, force=False):
476 pass

Referenced by searx.favicons.cache.FaviconCacheSQLite.set().

+ Here is the caller graph for this function:

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

453 def set(self, resolver: str, authority: str, mime: str | None, data: bytes | None) -> bool:
454
455 if data is None:
456 data = FALLBACK_ICON
457 mime = None
458
459 elif mime is None:
460 logger.error(
461 "favicon resolver %s tries to cache mime-type None for authority %s",
462 resolver,
463 authority,
464 )
465 return False
466
467 digest = hashlib.sha256(data).hexdigest()
468 self._data[digest] = data
469 self._sha_mime[f"{resolver}:{authority}"] = (digest, mime)
470 return True
471

References searx.favicons.cache.FaviconCacheMEM._data, and searx.favicons.cache.FaviconCacheMEM._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 472 of file cache.py.

472 def state(self):
473 return FaviconCacheStats(favicons=len(self._data.keys()))
474

References searx.favicons.cache.FaviconCacheMEM._data.

Member Data Documentation

◆ _data

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

◆ _sha_mime

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

◆ cfg


The documentation for this class was generated from the following file: