sieve.cache 0.0.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,19 @@
1
+ [run]
2
+ branch = True
3
+ source = sieve_cache
4
+ omit =
5
+ __init__.py
6
+ concurrency = multiprocessing,thread
7
+ [report]
8
+ ignore_errors = True
9
+ exclude_lines =
10
+ pragma: no cover
11
+ def __repr__
12
+ if self.debug:
13
+ if settings.DEBUG
14
+ raise AssertionError
15
+ raise NotImplementedError
16
+ if 0:
17
+ if __name__ == .__main__.:
18
+ class .*\bProtocol\):
19
+ @(abc\.)?abstractmethod
@@ -0,0 +1,35 @@
1
+ name: Python CI
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+ pull_request:
8
+
9
+ jobs:
10
+ tox:
11
+ runs-on: ubuntu-latest
12
+ strategy:
13
+ fail-fast: false
14
+ matrix:
15
+ python-version: ["3.10", "3.11", "3.12"]
16
+
17
+ steps:
18
+ - name: Checkout repository
19
+ uses: actions/checkout@v4
20
+
21
+ - name: Set up Python ${{ matrix.python-version }}
22
+ uses: actions/setup-python@v5
23
+ with:
24
+ python-version: ${{ matrix.python-version }}
25
+
26
+ - name: Set up uv
27
+ uses: astral-sh/setup-uv@v5
28
+ with:
29
+ enable-cache: true
30
+
31
+ - name: Install tox
32
+ run: uv tool install tox --with tox-uv
33
+
34
+ - name: Run tox (tests + lint)
35
+ run: tox -e py3,pep8
@@ -0,0 +1,53 @@
1
+ name: Release to PyPI
2
+
3
+ on:
4
+ release:
5
+ types: [published]
6
+
7
+ jobs:
8
+ build:
9
+ runs-on: ubuntu-latest
10
+
11
+ steps:
12
+ - name: Checkout repository
13
+ uses: actions/checkout@v4
14
+
15
+ - name: Set up Python
16
+ uses: actions/setup-python@v5
17
+ with:
18
+ python-version: "3.x"
19
+
20
+ - name: Build distribution artifacts
21
+ run: |
22
+ python -m pip install build
23
+ python -m build
24
+
25
+ - name: Upload distribution artifacts
26
+ uses: actions/upload-artifact@v4
27
+ with:
28
+ name: python-package-distributions
29
+ path: dist/
30
+
31
+ upload-to-pypi:
32
+ needs: build
33
+ runs-on: ubuntu-latest
34
+ environment:
35
+ name: pypi
36
+ url: https://pypi.org/p/sieve.cache
37
+ permissions:
38
+ id-token: write
39
+
40
+ steps:
41
+ - name: Download distribution artifacts
42
+ uses: actions/download-artifact@v4
43
+ with:
44
+ name: python-package-distributions
45
+ path: dist/
46
+
47
+ - name: Publish to PyPI
48
+ uses: pypa/gh-action-pypi-publish@release/v1
49
+ with:
50
+ skip-existing: true
51
+ verify-metadata: false
52
+ verbose: true
53
+ packages-dir: dist/
@@ -0,0 +1,161 @@
1
+ ### Python template
2
+ # Byte-compiled / optimized / DLL files
3
+ __pycache__/
4
+ *.py[cod]
5
+ *$py.class
6
+
7
+ # C extensions
8
+ *.so
9
+
10
+ # Distribution / packaging
11
+ .Python
12
+ build/
13
+ develop-eggs/
14
+ dist/
15
+ downloads/
16
+ eggs/
17
+ .eggs/
18
+ lib/
19
+ lib64/
20
+ parts/
21
+ sdist/
22
+ var/
23
+ wheels/
24
+ share/python-wheels/
25
+ *.egg-info/
26
+ .installed.cfg
27
+ *.egg
28
+ MANIFEST
29
+
30
+ # PyInstaller
31
+ # Usually these files are written by a python script from a template
32
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
33
+ *.manifest
34
+ *.spec
35
+
36
+ # Installer logs
37
+ pip-log.txt
38
+ pip-delete-this-directory.txt
39
+
40
+ # Unit test / coverage reports
41
+ htmlcov/
42
+ .tox/
43
+ .nox/
44
+ .coverage
45
+ .coverage.*
46
+ .cache
47
+ nosetests.xml
48
+ coverage.xml
49
+ *.cover
50
+ *.py,cover
51
+ .hypothesis/
52
+ .pytest_cache/
53
+ cover/
54
+
55
+ # Translations
56
+ *.mo
57
+ *.pot
58
+
59
+ # Django stuff:
60
+ *.log
61
+ local_settings.py
62
+ db.sqlite3
63
+ db.sqlite3-journal
64
+
65
+ # Flask stuff:
66
+ instance/
67
+ .webassets-cache
68
+
69
+ # Scrapy stuff:
70
+ .scrapy
71
+
72
+ # Sphinx documentation
73
+ docs/_build/
74
+
75
+ # PyBuilder
76
+ .pybuilder/
77
+ target/
78
+
79
+ # Jupyter Notebook
80
+ .ipynb_checkpoints
81
+
82
+ # IPython
83
+ profile_default/
84
+ ipython_config.py
85
+
86
+ # pyenv
87
+ # For a library or package, you might want to ignore these files since the code is
88
+ # intended to run in multiple environments; otherwise, check them in:
89
+ # .python-version
90
+
91
+ # pipenv
92
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
93
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
94
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
95
+ # install all needed dependencies.
96
+ #Pipfile.lock
97
+
98
+ # poetry
99
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
100
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
101
+ # commonly ignored for libraries.
102
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
103
+ #poetry.lock
104
+
105
+ # pdm
106
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
107
+ #pdm.lock
108
+ # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
109
+ # in version control.
110
+ # https://pdm.fming.dev/#use-with-ide
111
+ .pdm.toml
112
+
113
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
114
+ __pypackages__/
115
+
116
+ # Celery stuff
117
+ celerybeat-schedule
118
+ celerybeat.pid
119
+
120
+ # SageMath parsed files
121
+ *.sage.py
122
+
123
+ # Environments
124
+ .env
125
+ .venv
126
+ env/
127
+ venv/
128
+ ENV/
129
+ env.bak/
130
+ venv.bak/
131
+
132
+ # Spyder project settings
133
+ .spyderproject
134
+ .spyproject
135
+
136
+ # Rope project settings
137
+ .ropeproject
138
+
139
+ # mkdocs documentation
140
+ /site
141
+
142
+ # mypy
143
+ .mypy_cache/
144
+ .dmypy.json
145
+ dmypy.json
146
+
147
+ # Pyre type checker
148
+ .pyre/
149
+
150
+ # pytype static type analyzer
151
+ .pytype/
152
+
153
+ # Cython debug symbols
154
+ cython_debug/
155
+
156
+ # PyCharm
157
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
158
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
159
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
160
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
161
+ .idea/
@@ -0,0 +1,33 @@
1
+ # See https://pre-commit.com for more information
2
+ # See https://pre-commit.com/hooks.html for more hooks
3
+ repos:
4
+ - repo: https://github.com/pre-commit/pre-commit-hooks
5
+ rev: 3298ddab3c13dd77d6ce1fc0baf97691430d84b0 # v4.3.0
6
+ hooks:
7
+ - id: trailing-whitespace
8
+ # Replaces or checks mixed line ending
9
+ - id: mixed-line-ending
10
+ args: ['--fix', 'lf']
11
+ exclude: '.*\.(svg)$'
12
+ - id: end-of-file-fixer
13
+ # Forbid files which have a UTF-8 byte-order marker
14
+ - id: check-byte-order-marker
15
+ # Checks that non-binary executables have a proper shebang
16
+ - id: check-executables-have-shebangs
17
+ # Check for files that contain merge conflict strings.
18
+ - id: check-merge-conflict
19
+ - id: debug-statements
20
+ - id: check-yaml
21
+ files: .*\.(yaml|yml)$
22
+ - id: check-added-large-files
23
+ - repo: local
24
+ hooks:
25
+ - id: flake8
26
+ name: flake8
27
+ additional_dependencies:
28
+ - hacking>=3.1.0,<3.2.0
29
+ language: python
30
+ entry: flake8
31
+ files: '^.*\.py$'
32
+ exclude: '^(doc|releasenotes|tools)/.*$'
33
+ args: ['--config=setup.cfg']
@@ -0,0 +1,3 @@
1
+ [DEFAULT]
2
+ test_path=${OS_TEST_PATH:-./sieve_cache/tests}
3
+ top_dir=./
@@ -0,0 +1,77 @@
1
+ Metadata-Version: 2.4
2
+ Name: sieve.cache
3
+ Version: 0.0.1
4
+ Summary: A simple implementation of SIEVE caching algorithm
5
+ Author-email: Pham Le Gia Dai <daipham.3213@gmail.com>
6
+ License: Apache-2.0
7
+ Classifier: Intended Audience :: Information Technology
8
+ Classifier: License :: OSI Approved :: Apache Software License
9
+ Classifier: Programming Language :: Python
10
+ Classifier: Programming Language :: Python :: 3 :: Only
11
+ Classifier: Programming Language :: Python :: 3.10
12
+ Requires-Python: >=3.10
13
+ Requires-Dist: dogpile-cache>=1.3.0
14
+ Requires-Dist: iso8601>=2.1.0
15
+ Requires-Dist: stevedore>=5.1.0
16
+ Provides-Extra: redis
17
+ Requires-Dist: redis; extra == 'redis'
18
+ Description-Content-Type: text/markdown
19
+
20
+ # sieve.cache
21
+
22
+ `sieve.cache` is a lightweight Python cache utility that implements the
23
+ SIEVE eviction algorithm on top of `dogpile.cache` backends.
24
+
25
+ ## Project Summary
26
+
27
+ - Implements a `Sieve` cache with a decorator-based API.
28
+ - Uses a doubly linked list (`head`, `tail`, `hand`) to track entries.
29
+ - Applies SIEVE eviction using a `visited` bit on each node.
30
+ - Integrates with `dogpile.cache` regions and key generation.
31
+ - Includes an in-memory backend adapter (`sieve_cache.memory`).
32
+
33
+ ## How It Works
34
+
35
+ When a decorated function is called:
36
+
37
+ 1. A cache key is generated from function arguments.
38
+ 2. If the key exists, the node is marked as visited and returned.
39
+ 3. On a miss, the function is executed and result cached.
40
+ 4. If cache size reaches `max_size`, an item is evicted by SIEVE.
41
+
42
+ The eviction pointer (`hand`) scans backward, clears `visited=True` nodes,
43
+ and removes the first unvisited candidate.
44
+
45
+ ## Installation
46
+
47
+ Install from source:
48
+
49
+ ```bash
50
+ pip install sieve-cache
51
+ ```
52
+
53
+ ## Quick Usage
54
+
55
+ ```python
56
+ import sieve_cache
57
+
58
+ cache = sieve_cache.create_sieve(backend="sieve_cache.memory")
59
+
60
+ @cache.cache(max_size=128)
61
+ def expensive_call(x: int) -> int:
62
+ return x * x
63
+
64
+ print(expensive_call(5))
65
+ print(expensive_call(5)) # cached
66
+ ```
67
+
68
+ ## Project Layout
69
+
70
+ - `sieve_cache/sieve.py`: Core SIEVE cache implementation and decorator.
71
+ - `sieve_cache/node.py`: Cache node model used by linked-list structure.
72
+ - `sieve_cache/backends/memory.py`: In-memory `dogpile.cache` backend.
73
+ - `sieve_cache/__init__.py`: Region/backend configuration and factory helpers.
74
+
75
+ ## References
76
+
77
+ - [SIEVE is Simpler than LRU: an Efficient Turn-Key Eviction Algorithm for Web Caches](https://cachemon.github.io/SIEVE-website/)
@@ -0,0 +1,58 @@
1
+ # sieve.cache
2
+
3
+ `sieve.cache` is a lightweight Python cache utility that implements the
4
+ SIEVE eviction algorithm on top of `dogpile.cache` backends.
5
+
6
+ ## Project Summary
7
+
8
+ - Implements a `Sieve` cache with a decorator-based API.
9
+ - Uses a doubly linked list (`head`, `tail`, `hand`) to track entries.
10
+ - Applies SIEVE eviction using a `visited` bit on each node.
11
+ - Integrates with `dogpile.cache` regions and key generation.
12
+ - Includes an in-memory backend adapter (`sieve_cache.memory`).
13
+
14
+ ## How It Works
15
+
16
+ When a decorated function is called:
17
+
18
+ 1. A cache key is generated from function arguments.
19
+ 2. If the key exists, the node is marked as visited and returned.
20
+ 3. On a miss, the function is executed and result cached.
21
+ 4. If cache size reaches `max_size`, an item is evicted by SIEVE.
22
+
23
+ The eviction pointer (`hand`) scans backward, clears `visited=True` nodes,
24
+ and removes the first unvisited candidate.
25
+
26
+ ## Installation
27
+
28
+ Install from source:
29
+
30
+ ```bash
31
+ pip install sieve-cache
32
+ ```
33
+
34
+ ## Quick Usage
35
+
36
+ ```python
37
+ import sieve_cache
38
+
39
+ cache = sieve_cache.create_sieve(backend="sieve_cache.memory")
40
+
41
+ @cache.cache(max_size=128)
42
+ def expensive_call(x: int) -> int:
43
+ return x * x
44
+
45
+ print(expensive_call(5))
46
+ print(expensive_call(5)) # cached
47
+ ```
48
+
49
+ ## Project Layout
50
+
51
+ - `sieve_cache/sieve.py`: Core SIEVE cache implementation and decorator.
52
+ - `sieve_cache/node.py`: Cache node model used by linked-list structure.
53
+ - `sieve_cache/backends/memory.py`: In-memory `dogpile.cache` backend.
54
+ - `sieve_cache/__init__.py`: Region/backend configuration and factory helpers.
55
+
56
+ ## References
57
+
58
+ - [SIEVE is Simpler than LRU: an Efficient Turn-Key Eviction Algorithm for Web Caches](https://cachemon.github.io/SIEVE-website/)
@@ -0,0 +1,42 @@
1
+ [build-system]
2
+ requires = ["hatchling", "hatch-vcs", "hatch-requirements-txt"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "sieve.cache"
7
+ dynamic = ["version", "dependencies"]
8
+ description = "A simple implementation of SIEVE caching algorithm"
9
+ readme = "README.md"
10
+ requires-python = ">=3.10"
11
+ license = { text = "Apache-2.0" }
12
+ authors = [
13
+ { name = "Pham Le Gia Dai", email = "daipham.3213@gmail.com" },
14
+ ]
15
+ classifiers = [
16
+ "Intended Audience :: Information Technology",
17
+ "License :: OSI Approved :: Apache Software License",
18
+ "Programming Language :: Python",
19
+ "Programming Language :: Python :: 3 :: Only",
20
+ "Programming Language :: Python :: 3.10",
21
+ ]
22
+
23
+ [project.optional-dependencies]
24
+ redis = ["redis"]
25
+
26
+ [project.entry-points."dogpile.cache"]
27
+ "sieve_cache.memory" = "sieve_cache.backends.memory:InMemoryDriver"
28
+
29
+ [tool.hatch.build.targets.wheel]
30
+ packages = ["sieve_cache"]
31
+
32
+ [tool.hatch.version]
33
+ source = "vcs"
34
+
35
+ [tool.hatch.metadata.hooks.requirements_txt]
36
+ files = ["requirements.txt"]
37
+
38
+ [tool.ruff]
39
+ line-length = 79
40
+
41
+ [tool.ruff.format]
42
+ docstring-code-format = true
@@ -0,0 +1,15 @@
1
+ # Licensed under the Apache License, Version 2.0 (the "License"); you may
2
+ # not use this file except in compliance with the License. You may obtain
3
+ # a copy of the License at
4
+ # #
5
+ # http://www.apache.org/licenses/LICENSE-2.0
6
+ # #
7
+ # Unless required by applicable law or agreed to in writing, software
8
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10
+ # License for the specific language governing permissions and limitations
11
+ # under the License.
12
+
13
+ stevedore>=5.1.0
14
+ dogpile.cache>=1.3.0
15
+ iso8601>=2.1.0