Transparent Redis caching for SQLModel
Project description
sqlmodel-cache
Transparent Redis caching for SQLModel — cache session.get() lookups with a single class attribute.
Installation
pip install sqlmodel-cache
# With async support:
pip install "sqlmodel-cache[async]"
Quick Example
import redis
from sqlmodel import Field, Session, SQLModel, create_engine
from sqlmodel_cache import CacheConfig, SQLModelCache
from sqlmodel_cache.transport import RedisSyncTransport
SQLModelCache.configure(
transport=RedisSyncTransport(redis.Redis.from_url("redis://localhost:6379")),
default_ttl=300,
)
class Hero(SQLModel, table=True):
__cache_config__ = CacheConfig(ttl=600)
id: int | None = Field(default=None, primary_key=True)
name: str = ""
engine = create_engine("sqlite:///heroes.db")
SQLModel.metadata.create_all(engine)
with Session(engine) as session:
hero = session.get(Hero, 1) # cache miss → queries DB
with Session(engine) as session:
hero = session.get(Hero, 1) # cache hit → returns from Redis
Documentation
Full documentation is available at emzelim.github.io/sqlmodel-cache.
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 sqlmodel_cache-0.1.1.tar.gz.
File metadata
- Download URL: sqlmodel_cache-0.1.1.tar.gz
- Upload date:
- Size: 522.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
999fbcc3a6843aac7d19dd99649ccd5e70318e86283699a72898333aaee55738
|
|
| MD5 |
888421ce02769b00e7eeb730f607f548
|
|
| BLAKE2b-256 |
67a9ca0993891784b59bd594acbef19572fbe1ed6b84c203f0f73f2c03dff080
|
Provenance
The following attestation bundles were made for sqlmodel_cache-0.1.1.tar.gz:
Publisher:
publish.yml on Emzelim/sqlmodel-cache
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
sqlmodel_cache-0.1.1.tar.gz -
Subject digest:
999fbcc3a6843aac7d19dd99649ccd5e70318e86283699a72898333aaee55738 - Sigstore transparency entry: 982272191
- Sigstore integration time:
-
Permalink:
Emzelim/sqlmodel-cache@4d268da67e5bebced4d0c528b33c14ccfc595ae6 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/Emzelim
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@4d268da67e5bebced4d0c528b33c14ccfc595ae6 -
Trigger Event:
push
-
Statement type:
File details
Details for the file sqlmodel_cache-0.1.1-py3-none-any.whl.
File metadata
- Download URL: sqlmodel_cache-0.1.1-py3-none-any.whl
- Upload date:
- Size: 18.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5e781dc38eed86ac6e8394c1c1a5d2646d27c1e233aa69158613709347588040
|
|
| MD5 |
5b63a22689576fa77eb2421612cb8737
|
|
| BLAKE2b-256 |
df319f67a98394283c674bde861ecc5e9c432188b957a30af23fb889177ad701
|
Provenance
The following attestation bundles were made for sqlmodel_cache-0.1.1-py3-none-any.whl:
Publisher:
publish.yml on Emzelim/sqlmodel-cache
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
sqlmodel_cache-0.1.1-py3-none-any.whl -
Subject digest:
5e781dc38eed86ac6e8394c1c1a5d2646d27c1e233aa69158613709347588040 - Sigstore transparency entry: 982272209
- Sigstore integration time:
-
Permalink:
Emzelim/sqlmodel-cache@4d268da67e5bebced4d0c528b33c14ccfc595ae6 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/Emzelim
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@4d268da67e5bebced4d0c528b33c14ccfc595ae6 -
Trigger Event:
push
-
Statement type: