jina.drivers.cache

Module for the Drivers for the Cache.

class jina.drivers.cache.BaseCacheDriver(with_serialization=False, *args, **kwargs)[source]

Bases: jina.drivers.index.BaseIndexDriver

A driver related to BaseCache.

Parameters
  • with_serialization (bool) – feed serialized Document to the CacheIndexer

  • args – additional positional arguments which are just used for the parent initialization

  • kwargs – additional key value arguments which are just used for the parent initialization

on_miss(req_doc, value)[source]

Call when document is missing.

The default behavior is to add to cache when miss.

Parameters
  • req_doc (Document) – the document in the request but missed in the cache

  • value (bytes) – the data besides the req_doc.id to be passed through to the executors

Return type

None

on_hit(req_doc, hit_result)[source]

Call when cache is hit for a document.

Parameters
  • req_doc (Document) – the document in the request and hit in the cache

  • hit_result (Any) – the hit result returned by the cache

Return type

None

static hash_doc(doc, fields)[source]

Calculate hash by which we cache.

Parameters
  • doc (Document) – the Document

  • fields (List[str]) – the list of fields

Return type

bytes

Returns

the hash value of the fields

runtime: Optional[ZEDRuntime]
class jina.drivers.cache.TaggingCacheDriver(tags, *args, **kwargs)[source]

Bases: jina.drivers.cache.BaseCacheDriver

A driver for labelling the hit-cache docs with certain tags.

Create a new TaggingCacheDriver.

Parameters
  • tags (Dict) – the tags to be updated on hit docs

  • args – additional positional arguments which are just used for the parent initialization

  • kwargs – additional key value arguments which are just used for the parent initialization

on_hit(req_doc, hit_result)[source]

Call when cache is hit for a document.

Parameters
  • req_doc (Document) – the document requested

  • hit_result (Any) – the result of the hit

Return type

None

runtime: Optional[ZEDRuntime]