Skip to content

Key matcher

Defines a base class for hybrid cache used in Gen AI applications.

Authors

Henry Wicaksono (henry.wicaksono@gdplabs.id)

References

NONE

BaseKeyMatcher

Bases: ABC

A base class for key matcher classes used in hybrid caches.

The key matcher is a framework that can be used by hybrid caches to retrieve the key that matches the input key using different strategies as defined in the subclasses.

clear() abstractmethod async

Clear all the keys that are stored as additional information during the matching process.

This method must be implemented by the subclasses to define the logic for clearing all the keys that are stored as additional information during the matching process.

Raises:

Type Description
NotImplementedError

If the method is not implemented.

delete(key) abstractmethod async

Delete the key stored as additional information during the matching process.

This method must be implemented by the subclasses to define the logic for deleting the key stored as additional information during the matching process.

Parameters:

Name Type Description Default
key str | list[str]

The key(s) to be deleted.

required

Raises:

Type Description
NotImplementedError

If the method is not implemented.

retrieve(key, cached_keys) abstractmethod async

Retrieve the key that matches the input key.

This method must be implemented by the subclasses to define the logic for retrieving the matched key.

Parameters:

Name Type Description Default
key str

The input key to be matched.

required
cached_keys set[str]

The set of cached keys to be matched.

required

Returns:

Type Description
str | None

str | None: The matched key, if found. Otherwise, None.

Raises:

Type Description
NotImplementedError

If the method is not implemented.

store(key) abstractmethod async

Store the key as additional information during the matching process.

This method must be implemented by the subclasses to define the logic for storing the key as additional information during the matching process.

Parameters:

Name Type Description Default
key str

The key to be stored as additional information during the matching process.

required

Raises:

Type Description
NotImplementedError

If the method is not implemented.