grove.caches package

Grove cache handlers.

class grove.caches.BaseCache[source]

Bases: ABC

abstract delete(pk: str, sk: str, constraint: str | None = None)[source]

Deletes an entry with the given key from the cache.

If the implementation does not differentiate partition and sort keys, these values should be combined in an appropriate way to form a cache key.

Parameters:
  • pk – Partition key of the value to delete.

  • sk – Sort key of the value to delete.

  • constraint – An optional condition to use during the delete. The value provided as the condition must match for the delete to be successful.

Raises:

DataFormatException – The provided constraint was not satisfied.

abstract get(pk: str, sk: str) str[source]

Gets the value for the given key from the cache.

If the implementation does not differentiate partition and sort keys, these values should be combined in an appropriate way to form a cache key.

Parameters:
  • pk – Partition key of the value to retrieve.

  • sk – Sort key of the value to retrieve.

Returns:

The value from the cache.

abstract set(pk: str, sk: str, value: str, not_set: bool = False, constraint: str | None = None)[source]

Stores the value for the given key in a cache.

If the implementation does not differentiate partition and sort keys, these values should be combined in an appropriate way to form a cache key.

Parameters:
  • pk – Partition key of the value to store.

  • sk – Sort key of the value to store.

  • value – Value to store.

  • not_set – Specifies whether the value must not already be set in the cache for the set to be successful.

  • constraint – An optional condition to use set operation. If provided, the currently cached value must match for the delete to be successful.

Raises:
  • ValueError – An incompatible set of parameters were provided.

  • DataFormatException – The provided constraint was not satisfied.

Submodules

grove.caches.aws_dynamodb module

Grove AWS DynamoDB cache handler.

class grove.caches.aws_dynamodb.Configuration(_env_file: str | PathLike | List[str | PathLike] | Tuple[str | PathLike, ...] | None = '<object object>', _env_file_encoding: str | None = None, _env_nested_delimiter: str | None = None, _secrets_dir: str | PathLike | None = None, *, table: str = 'grove', url: str | None = None, assume_role_arn: str | None = None, table_region: str | None = 'us-east-1')[source]

Bases: BaseSettings

Defines environment variables used to configure the AWS DynamoDB handler.

This should also include any appropriate default values for fields which are not required.

class Config[source]

Bases: object

Allow environment variable override of configuration fields.

This also enforce a prefix for all environment variables for this handler. As an example the field assume_role_arn would be set using the environment variable GROVE_CACHE_AWS_DYNAMODB_ASSUME_ROLE_ARN.

case_insensitive = True
env_prefix = 'GROVE_CACHE_AWS_DYNAMODB_'
assume_role_arn: str | None
table: str
table_region: str | None
url: str | None
class grove.caches.aws_dynamodb.Handler[source]

Bases: BaseCache

This cache handler allows Grove to write objects into an AWS DynamoDB cache.

delete(pk: str, sk: str, constraint: str | None = None)[source]

Deletes an entry from DynamoDB that has the given PK / SK.

Parameters:
  • pk – Partition key of the value to delete.

  • sk – Sort key of the value to delete.

  • constraint – An optional condition to use during the delete. The value provided as the condition must match for the delete to be successful.

Raises:
get(pk: str, sk: str) str[source]

Retrieve an value with the given PK / SK.

Parameters:
  • pk – Partition key of the value to retrieve.

  • sk – Sort key of the value to retrieve.

Raises:
Returns:

Value from the cache.

set(pk: str, sk: str, value: str, not_set: bool = False, constraint: str | None = None)[source]

Stores the value for the given key in DynamoDB.

Parameters:
  • pk – Partition key of the value to store.

  • sk – Sort key of the value to store.

  • value – Value to store.

  • not_set – Specifies whether the value must not already be set in the cache for the set to be successful.

  • constraint – An optional condition to use set operation. If provided, the currently cached value must match for the delete to be successful.

Raises:
  • ValueError – An incompatible set of parameters were provided.

  • AccessException – An issue occurred when storing the value.

  • DataFormatException – The provided constraint was not satisfied.

grove.caches.local_file module

Grove local file cache handler.

class grove.caches.local_file.Configuration(_env_file: str | PathLike | List[str | PathLike] | Tuple[str | PathLike, ...] | None = '<object object>', _env_file_encoding: str | None = None, _env_nested_delimiter: str | None = None, _secrets_dir: str | PathLike | None = None, *, path: str)[source]

Bases: BaseSettings

Defines environment variables used to configure the local file cache handler.

This should also include any appropriate default values for fields which are not required.

class Config[source]

Bases: object

Allow environment variable override of configuration fields.

This also enforce a prefix for all environment variables for this handler. As an example the field path would be set using the environment variable GROVE_CACHE_LOCAL_FILE_PATH.

case_insensitive = True
env_prefix = 'GROVE_CACHE_LOCAL_FILE_'
path: str
class grove.caches.local_file.Handler[source]

Bases: BaseCache

A local file backed cache for pointers and other Grove data.

delete(pk: str, sk: str, constraint: str | None = None)[source]

Deletes an entry from local file backed cache that has the given key.

Parameters:
  • pk – Partition key of the value to delete.

  • sk – Sort key of the value to delete.

  • constraint – An optional condition to use during the delete. The value provided as the condition must match for the delete to be successful.

Raises:

DataFormatException – The provided constraint was not satisfied.

get(pk: str, sk: str) str[source]

Retrieve a value from a local file backed cache with the given key.

Parameters:
  • pk – Partition key of the value to retrieve.

  • sk – Sort key of the value to retrieve.

Raises:

NotFoundException – No value was found.

Returns:

Value from the cache.

set(pk: str, sk: str, value: str, not_set: bool = False, constraint: str | None = None)[source]

Stores the value for the given key in a local file backed cache.

Parameters:
  • pk – Partition key of the value to save.

  • sk – Sort key of the value to save.

  • value – Value to save.

  • not_set – Specifies whether the value must not already be set in the cache for the set to be successful.

  • constraint – An optional condition to use set operation. If provided, the currently cached value must match for the delete to be successful.

Raises:
  • ValueError – An incompatible set of parameters were provided.

  • DataFormatException – The provided constraint was not satisfied.

grove.caches.local_memory module

Grove in memory cache handler.

class grove.caches.local_memory.Handler[source]

Bases: BaseCache

A volatile in-memory backed cache for pointers and other Grove data.

delete(pk: str, sk: str, constraint: str | None = None)[source]

Deletes an entry from dict that has the given PK / SK.

Parameters:
  • pk – Partition key of the value to delete.

  • sk – Sort key of the value to delete.

  • constraint – An optional condition to use during the delete. The value provided as the condition must match for the delete to be successful.

Raises:

DataFormatException – The provided constraint was not satisfied.

get(pk: str, sk: str) str[source]

Retrieve a value with the given PK / SK.

Parameters:
  • pk – Partition key of the value to retrieve.

  • sk – Sort key of the value to retrieve.

Raises:

NotFoundException – No value was found.

Returns:

Value from the cache.

set(pk: str, sk: str, value: str, not_set: bool = False, constraint: str | None = None)[source]

Stores the value for the given key in a local dict.

Parameters:
  • pk – Partition key of the value to save.

  • sk – Sort key of the value to save.

  • value – Value to save.

  • not_set – Specifies whether the value must not already be set in the cache for the set to be successful.

  • constraint – An optional condition to use set operation. If provided, the currently cached value must match for the delete to be successful.

Raises:
  • ValueError – An incompatible set of parameters were provided.

  • DataFormatException – The provided constraint was not satisfied.