Skip to content

cattle_grid.extensions.examples.cache

This cache stores objects temporally in a key value database

Sample configuration

cattle_grid.toml
[[extensions]]
module = "cattle_grid.extensions.examples.cache"
lookup_order = 4
config = { connection_url = "redis://cattle_grid_redis", duration = 3600 }

The duration is expressed in seconds. By using the special connection_url :memory: the cache will be replaced by fakeredis. This means that the cache is in memory and no external key value database is necessary. This is useful for testing, but not recommended for production use.

config

CacheConfiguration

Bases: BaseModel

Parameters:

Name Type Description Default
connection_url str
'redis://localhost:6379'
duration int
3600
Source code in cattle_grid/extensions/examples/cache/config.py
4
5
6
7
8
9
class CacheConfiguration(BaseModel):
    connection_url: str = Field(default="redis://localhost:6379")
    """Connection url to the key value instance, e.g. redis"""

    duration: int = Field(default=3600)
    """Duration to cache in second"""

connection_url class-attribute instance-attribute

connection_url: str = Field(
    default="redis://localhost:6379"
)

Connection url to the key value instance, e.g. redis

duration class-attribute instance-attribute

duration: int = Field(default=3600)

Duration to cache in second

dependencies

CacheClient module-attribute

CacheClient = Annotated[Redis, Depends(get_cache)]

The cache client

CacheConfig module-attribute

CacheConfig = Annotated[
    CacheConfiguration, Depends(get_config)
]

The configuration object passed when instantiating the extension