Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose cache_info #9

Merged
merged 4 commits into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,14 @@ jobs:
runs-on: ubuntu-latest
needs: [get-new-tag, publish]
env:
POETRY_VERSION: 1.1.7
POETRY_VERSION: 1.8.2
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- uses: actions/setup-python@v2
with:
python-version: 3.7
python-version: 3.10
- name: Install dependencies
run: |
pip install poetry==${{ env.POETRY_VERSION }}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.7, 3.8, 3.9, "3.10"]
python-version: [3.9, "3.10", "3.11", "3.12"]
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
Expand All @@ -15,7 +15,7 @@ jobs:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
pip install poetry==1.1.7
pip install poetry==1.8.2
poetry config virtualenvs.create false
poetry install --no-interaction --no-ansi
- name: QA with flake8, black, isort and mypy
Expand Down
25 changes: 8 additions & 17 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,12 @@ repos:
- id: end-of-file-fixer
exclude: "LICENSE"
- id: trailing-whitespace
- repo: https://github.com/psf/black
rev: 22.6.0
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.3.3
hooks:
- id: black
- repo: https://github.com/pycqa/isort
rev: 5.10.1
hooks:
- id: isort
- repo: https://github.com/pycqa/flake8
rev: 4.0.1
hooks:
- id: flake8
additional_dependencies:
- flake8-docstrings==1.6.0
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.942
hooks:
- id: mypy
# Run the linter.
- id: ruff
args: [ --fix ]
# Run the formatter.
- id: ruff-format
4 changes: 3 additions & 1 deletion expiring_lru_cache/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Core functionality."""

import functools
import logging
from datetime import datetime, timedelta
Expand Down Expand Up @@ -39,7 +40,7 @@ def _expired(cached_func: Callable) -> bool:
def lru_cache(
expires_after: Optional[int] = None,
*args: Union[int, bool],
**kwargs: Union[int, bool]
**kwargs: Union[int, bool],
) -> Callable:
"""
LRU caching with expiration period.
Expand All @@ -65,6 +66,7 @@ def wrapper(*args: Union[int, bool], **kwargs: Union[int, bool]) -> Callable:
cached_func = _init_cache(func, expires_after, *args, **kwargs)
return cached_func(*args, **kwargs)

wrapper.cache_info = lambda: cached_func.cache_info()
return wrapper

return decorate
Empty file removed expiring_lru_cache/py.typed
Empty file.
1 change: 1 addition & 0 deletions expiring_lru_cache/version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
"""Package version information - this file is dynamically overwritten in CI."""

__version__ = "0.0.0-dev"
999 changes: 666 additions & 333 deletions poetry.lock

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions tests/test_basic.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Basic testing."""

from datetime import datetime
from functools import partial
from time import sleep
Expand Down Expand Up @@ -28,3 +29,11 @@ def test_expiration_basic() -> None:
p = partial(lru_cache(expires_after=2)(lambda: datetime.now()))
res = call_every_x_secs(p, 4)
assert any(el != res[0] for el in res)


def test_has_cache_info() -> None:
"""Test if cache has info."""
cf = lru_cache()(lambda: 1)
for _ in range(3):
cf()
assert cf.cache_info().hits != 0
1 change: 1 addition & 0 deletions tests/test_version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Test versioning mechanism."""

import expiring_lru_cache


Expand Down
Loading