Client for cacheia service that allows invalidation and other shenanigans
Project description
Cacheia CLient
This module contains a client that is responsible for communicating with the Cacheia API. It is a simple wrapper around the API endpoints, providing a more user-friendly interface for the user.
Installation
Install core with "schemas" optional to download schemas dependencies:
pip install -e ./client[schemas]
Client Methods
cache
: Takes instance (CreateRequest), creator (Infostar) and backend to create a new cache instance in the provided backend.get
: Retrieves all cached values with optional filters group (str), expires_range (tuple[float, float]) and creation_range(tuple[datetime, datetime]);get_key
: Fetches the cached value associated with key (str) - Optionally acceptsallow_expired
parameter to return a cached value even if expired.flush
: Clears all keys from the cache using with optional filters group (str), expires_range (tuple[float, float]) and creation_range(tuple[datetime, datetime]) and return the count of deleted records.flush_key
: Removes a single key from the cache using key (str).clear
: Removes all cached values from cache without any validation.
Code
The library exposes single functions that are similar to requests
and httpx
and also exposes a Client
class that can be used to define default value for API URL.
Examples
To create a cache instance with the client:
from cacheia_client import Client
from cacheia_schemas import CachedValue
default_url: str = "http://localhost:5000"
client = Client(url=default_url)
instance = CachedValue(key="key", value="value")
client.cache(instance=instance)
Or using the helper functions:
from cacheia_client import cache, configure
from cacheia_schemas import CachedValue
configure("http://localhost:5000")
instance = CachedValue(key="key", value="value")
cache(instance=instance)
Notice that when calling directly the functions, it is necessary to call "configure" with the desired URL. Otherwise, it will fail.
To get all cached values:
from cacheia_client import Client
default_url: str = "http://localhost:5000"
client = Client(url=default_url)
for v in client.get_all():
print(v)
To get a single cached value:
from cacheia_client import Client
default_url: str = "http://localhost:5000"
client = Client(url=default_url)
print(client.get(key="key"))
To flush all keys:
from cacheia_client import Client
default_url: str = "http://localhost:5000"
client = Client(url=default_url)
result = client.flush()
print(result.deleted_count)
To flush some keys:
from datetime import datetime
from cacheia_client import Client
default_url: str = "http://localhost:5000"
client = Client(url=default_url)
now = datetime.now().timestamp()
result = client.flush(expires_range=(now-10, now+10))
print(result.deleted_count)
To flush a single key:
from cacheia_client import Client
default_url: str = "http://localhost:5000"
client = Client(url=default_url)
result = client.flush_key(key="key")
print(result.deleted_count)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file cacheia_client-1.0.0.post3.tar.gz
.
File metadata
- Download URL: cacheia_client-1.0.0.post3.tar.gz
- Upload date:
- Size: 3.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1ca9ced65ff88e1e2ecda69c42e7ec3550c52c8891776413b5f916826b391081 |
|
MD5 | a765cd95157b543be544bf6ab4ebcb26 |
|
BLAKE2b-256 | db12f2586a4fea1a0baf59e468996acf9ccd200197a7f23e85e5804095851f32 |
File details
Details for the file cacheia_client-1.0.0.post3-py3-none-any.whl
.
File metadata
- Download URL: cacheia_client-1.0.0.post3-py3-none-any.whl
- Upload date:
- Size: 4.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9257bdad859a8cf4a3914daf01c185b129ce8b1778c524251d279e7d7218d2de |
|
MD5 | 41badd51cdc2a3885886c4c7d1ef4031 |
|
BLAKE2b-256 | f8348deb5de5b0f9b915023e675ae5b34d935672ce04a59b83db71bc23513067 |