Nexus / app /models /exact_cache.py
abc1181's picture
Add SQLite support, TTS/STT endpoints, db_utils helper
67b8c4a
Raw
History Blame Contribute Delete
733 Bytes
from sqlalchemy import text, Float, Index, Integer, Text, func
from sqlalchemy.orm import Mapped, mapped_column
from app.models.base import Base
class ExactCache(Base):
__tablename__ = "exact_cache"
cache_key: Mapped[str] = mapped_column(Text, primary_key=True)
response: Mapped[str] = mapped_column(Text, nullable=False)
created_at: Mapped[float] = mapped_column(
Float, server_default=func.extract("epoch", func.now())
)
expires_at: Mapped[float] = mapped_column(Float, nullable=False)
hit_count: Mapped[int] = mapped_column(Integer, default=0)
last_hit: Mapped[float | None] = mapped_column(Float, nullable=True)
__table_args__ = (Index("idx_exact_cache_expires", "expires_at"),)