Deterministic Redis key builder for cache-aside CRUD with cursor pagination
Project description
biplex-utils-cache-key-builder
Deterministic Redis key builder for cache-aside CRUD with cursor pagination.
Installation
pip install biplex-utils-cache-key-builder
Usage
from biplex_utils_cache_key_builder import CacheKeyBuilder
kb = CacheKeyBuilder(tenant="myapp", service="orders")
Single Entity Key
Cache a single entity (e.g., for GET by ID operations):
key = kb.entity_key(
entity="order",
company_id="company-123",
entity_id="order-456"
)
# Result: "myapp:orders:order:item:c:a1b2c3d4e5f6:order-456"
List Version Key
Track cache version for list invalidation:
key = kb.list_version_key(
entity="order",
companies_ids=["company-123", "company-456"]
)
# Result: "myapp:orders:order:list:c:b2c3d4e5f6a7:version"
List Cursor Key
Cache paginated list results with cursor-based pagination:
key = kb.list_cursor_key(
entity="order",
companies_ids=["company-123"],
version=1,
filters={"status": "active"},
sort=[{"field": "created_at", "direction": "desc"}],
cursor=None, # First page
limit=20
)
# Result: "myapp:orders:order:list:c:a1b2c3d4e5f6:v1:c3d4e5f6a7:start:20"
# For subsequent pages, pass the cursor:
key = kb.list_cursor_key(
entity="order",
companies_ids=["company-123"],
version=1,
filters={"status": "active"},
sort=[{"field": "created_at", "direction": "desc"}],
cursor={"id": "order-100", "created_at": "2024-01-15T10:00:00Z"},
limit=20
)
Key Features
- Deterministic: Same inputs always produce the same key
- Order-independent: Company IDs and dict keys are normalized before hashing
- Multi-tenant: Keys include tenant and service prefixes
- Cursor pagination: Built-in support for cursor-based pagination
- Version tracking: List version keys for cache invalidation strategies
Key Format
| Method | Format |
|---|---|
entity_key |
{tenant}:{service}:{entity}:item:c:{company_hash}:{entity_id} |
list_version_key |
{tenant}:{service}:{entity}:list:c:{companies_hash}:version |
list_cursor_key |
{tenant}:{service}:{entity}:list:c:{companies_hash}:v{version}:{query_hash}:{cursor_hash}:{limit} |
Hash Lengths
| Hash Type | Length | Used For |
|---|---|---|
| Company hash | 12 chars | Single/multiple company IDs |
| Query hash | 10 chars | Filters + sort parameters |
| Cursor hash | 8 chars | Pagination cursor |
Requirements
- Python 3.10+
License
MIT
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file biplex_utils_cache_key_builder-0.1.0.tar.gz.
File metadata
- Download URL: biplex_utils_cache_key_builder-0.1.0.tar.gz
- Upload date:
- Size: 6.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4539b9d6177728fe82f7973a14eb9f56ddcf1503918a0e73def9981db0c7a1cd
|
|
| MD5 |
01a5bcdb764f85ffe38922c46bf05422
|
|
| BLAKE2b-256 |
28b86a722e1bcfd0adc33818f5aa7b54cc481013a54d44a1e4bfeb1ed2fb54ec
|
File details
Details for the file biplex_utils_cache_key_builder-0.1.0-py3-none-any.whl.
File metadata
- Download URL: biplex_utils_cache_key_builder-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9b9005c407c53fddc53544d9e7d8722fcafb095ad6c3ae7e515c3d10fc2046c1
|
|
| MD5 |
5c1886a33517b8861a72c6e8273ac861
|
|
| BLAKE2b-256 |
20be20cbd83e6a1f0d64dc33f0986f0b9c592447ec7bc1090025f71c1ac53f9d
|