Metadata-Version: 2.4
Name: sqlmodel-cache
Version: 0.1.0
Summary: Transparent Redis caching for SQLModel
Project-URL: Homepage, https://github.com/emzelim/sqlmodel-cache
Project-URL: Documentation, https://emzelim.github.io/sqlmodel-cache
Project-URL: Repository, https://github.com/emzelim/sqlmodel-cache
Project-URL: Issues, https://github.com/emzelim/sqlmodel-cache/issues
Author: Emzelim
License: MIT
License-File: LICENSE
Keywords: cache,redis,sqlalchemy,sqlmodel
Classifier: Development Status :: 3 - Alpha
Classifier: Framework :: AsyncIO
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Database
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Typing :: Typed
Requires-Python: >=3.11
Requires-Dist: redis>=5.0
Requires-Dist: sqlmodel
Provides-Extra: async
Requires-Dist: redis[asyncio]>=5.0; extra == 'async'
Provides-Extra: benchmark
Requires-Dist: pytest-benchmark[histogram]>=4.0; extra == 'benchmark'
Description-Content-Type: text/markdown

# sqlmodel-cache

[![CI](https://github.com/emzelim/sqlmodel-cache/actions/workflows/ci.yml/badge.svg)](https://github.com/emzelim/sqlmodel-cache/actions/workflows/ci.yml)
[![PyPI](https://img.shields.io/pypi/v/sqlmodel-cache)](https://pypi.org/project/sqlmodel-cache/)

Transparent Redis caching for SQLModel — cache `session.get()` lookups with a single class attribute.

## Installation

```bash
pip install sqlmodel-cache
# With async support:
pip install "sqlmodel-cache[async]"
```

## Quick Example

```python
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](https://emzelim.github.io/sqlmodel-cache).

## License

MIT
