Skip to content

Commit 275a566

Browse files
authored
new index for key-expiration fields (#142)
1 parent 3fd9bb9 commit 275a566

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
"""adding index key-expiration.
2+
3+
Revision ID: fac14caeb10d
4+
Revises: a38663d192e5
5+
Create Date: 2025-03-06 11:43:44.497574
6+
7+
"""
8+
9+
from typing import Sequence, Union
10+
11+
from alembic import op
12+
13+
# revision identifiers, used by Alembic.
14+
revision: str = "fac14caeb10d"
15+
down_revision: Union[str, None] = "a38663d192e5"
16+
branch_labels: Union[str, Sequence[str], None] = None
17+
depends_on: Union[str, Sequence[str], None] = None
18+
19+
20+
def upgrade() -> None:
21+
op.create_index(
22+
"ix_cache_entries_key_expiration", "cache_entries", ["key", "expiration"]
23+
)
24+
25+
26+
def downgrade() -> None:
27+
op.drop_index("ix_cache_entries_key_expiration", "cache_entries")

cacholote/database.py

+2
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ class CacheEntry(Base):
4949
counter = sa.Column(sa.Integer)
5050
tag = sa.Column(sa.String)
5151

52+
__table_args__ = (sa.Index("ix_cache_entries_key_expiration", "key", "expiration"),)
53+
5254
@property
5355
def _result_as_string(self) -> str:
5456
return json.dumps(self.result)

0 commit comments

Comments
 (0)