onecache 0.6.0__tar.gz → 0.7.0__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.
@@ -1,23 +1,24 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: onecache
3
- Version: 0.6.0
3
+ Version: 0.7.0
4
4
  Summary: Python cache for sync and async code
5
+ License: MIT
5
6
  Author: Johanderson Mogollon
6
7
  Author-email: johander1822@gmail.com
7
- License: MIT
8
+ Requires-Python: >=3.8,<3.13
8
9
  Classifier: Development Status :: 5 - Production/Stable
9
10
  Classifier: Intended Audience :: Developers
10
- Classifier: Operating System :: OS Independent
11
11
  Classifier: License :: OSI Approved :: MIT License
12
- Classifier: Programming Language :: Python :: 3.6
13
- Classifier: Programming Language :: Python :: 3.7
12
+ Classifier: Operating System :: OS Independent
13
+ Classifier: Programming Language :: Python :: 3
14
14
  Classifier: Programming Language :: Python :: 3.8
15
15
  Classifier: Programming Language :: Python :: 3.9
16
16
  Classifier: Programming Language :: Python :: 3.10
17
17
  Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
18
19
  Classifier: Programming Language :: Python :: Implementation :: PyPy
19
20
  Description-Content-Type: text/markdown
20
- Provides-Extra: test
21
+
21
22
 
22
23
  [![Coverage Status](https://coveralls.io/repos/github/sonic182/onecache/badge.svg?branch=master)](https://coveralls.io/github/sonic182/onecache?branch=master)
23
24
  ![github status](https://github.com/sonic182/onecache/actions/workflows/python.yml/badge.svg)
@@ -27,7 +28,7 @@ Python cache for sync and async code.
27
28
 
28
29
  Cache uses LRU algoritm. Cache can optionally have TTL.
29
30
 
30
- Tested in python 3.7, 3.9, and pypy3.9 for windows, mac and linux (see github status badge), it should work in versions between them. It may work for python3.6
31
+ Tested in python 3.7, 3.9, 3.11 and pypy3.9 for windows, mac and linux (see github status badge), it should work in versions between them. It may work for python3.6
31
32
 
32
33
  # Usage
33
34
 
@@ -98,3 +99,4 @@ pip-sync requirements.txt test-requirements.txt
98
99
  3. commit - push - pull request
99
100
 
100
101
  Thanks :)
102
+
@@ -7,7 +7,7 @@ Python cache for sync and async code.
7
7
 
8
8
  Cache uses LRU algoritm. Cache can optionally have TTL.
9
9
 
10
- Tested in python 3.7, 3.9, and pypy3.9 for windows, mac and linux (see github status badge), it should work in versions between them. It may work for python3.6
10
+ Tested in python 3.7, 3.9, 3.11 and pypy3.9 for windows, mac and linux (see github status badge), it should work in versions between them. It may work for python3.6
11
11
 
12
12
  # Usage
13
13
 
@@ -2,13 +2,13 @@
2
2
 
3
3
  from collections import OrderedDict
4
4
  from contextlib import contextmanager
5
- from datetime import datetime, timedelta
5
+ from datetime import timedelta
6
6
  from sys import getsizeof
7
7
  from threading import Lock
8
8
  from typing import Any, Dict, Optional
9
9
 
10
10
  from onecache.cache_value import CacheValue
11
- from onecache.utils import IS_PYPY
11
+ from onecache.utils import IS_PYPY, utcnow
12
12
 
13
13
 
14
14
  class ExpirableCache(object):
@@ -26,10 +26,10 @@ class ExpirableCache(object):
26
26
  def __init__(
27
27
  self,
28
28
  size: int = 512,
29
- timeout: int = None,
29
+ timeout: Optional[int] = None,
30
30
  refresh_ttl=False,
31
31
  thread_safe=False,
32
- max_mem_size: int = None,
32
+ max_mem_size: Optional[int] = None,
33
33
  ):
34
34
  self.cache: Dict[str, CacheValue] = OrderedDict()
35
35
  self.timeout = timeout
@@ -49,7 +49,7 @@ class ExpirableCache(object):
49
49
  self._pop_one()
50
50
 
51
51
  if self.timeout:
52
- expire_at = datetime.utcnow() + timedelta(milliseconds=self.timeout)
52
+ expire_at = utcnow() + timedelta(milliseconds=self.timeout)
53
53
  value = CacheValue(data, expire_at)
54
54
  else:
55
55
  value = CacheValue(data)
@@ -108,7 +108,7 @@ class ExpirableCache(object):
108
108
  cache_value = self.cache.get(key)
109
109
  if cache_value and (milliseconds or self.timeout):
110
110
  ms = milliseconds if milliseconds else self.timeout
111
- expire_at = datetime.utcnow() + timedelta(milliseconds=ms)
111
+ expire_at = utcnow() + timedelta(milliseconds=ms)
112
112
  cache_value.refresh_ttl(expire_at)
113
113
 
114
114
  @classmethod
@@ -154,7 +154,7 @@ class LRUCache(ExpirableCache):
154
154
  with self._scoped():
155
155
  self._increment(cache_value)
156
156
  return cache_value.value
157
-
157
+
158
158
  return None
159
159
 
160
160
  def _increment(self, val: CacheValue):
@@ -1,14 +1,14 @@
1
1
  from datetime import datetime
2
2
  from sys import getsizeof
3
- from typing import Any
3
+ from typing import Any, Optional
4
4
 
5
- from onecache.utils import IS_PYPY
5
+ from onecache.utils import IS_PYPY, utcnow
6
6
 
7
7
 
8
8
  class CacheValue:
9
9
  """Dummy class for handling cache values."""
10
10
 
11
- def __init__(self, value: Any, expire_at: datetime = None):
11
+ def __init__(self, value: Any, expire_at: Optional[datetime] = None):
12
12
  self.size = None if IS_PYPY else getsizeof(value)
13
13
  self.access = 0
14
14
 
@@ -21,7 +21,7 @@ class CacheValue:
21
21
  def expired(self):
22
22
  """Check if value is expired."""
23
23
  if self.expire_at:
24
- return datetime.utcnow() > self.expire_at
24
+ return utcnow() > self.expire_at
25
25
  return False # pragma: no cover
26
26
 
27
27
  def refresh_ttl(self, expire_at: datetime):
@@ -0,0 +1,11 @@
1
+ import datetime
2
+ import platform
3
+ import sys
4
+
5
+ IS_PYPY = platform.python_implementation().lower().startswith("pypy")
6
+
7
+ def utcnow():
8
+ if sys.version_info >= (3, 11):
9
+ return datetime.datetime.now(datetime.UTC)
10
+ else:
11
+ return datetime.datetime.utcnow()
@@ -0,0 +1,40 @@
1
+ [tool.poetry]
2
+ name = "onecache"
3
+ version = "0.7.0"
4
+ description = "Python cache for sync and async code"
5
+ authors = ["Johanderson Mogollon <johander1822@gmail.com>"]
6
+ license = "MIT"
7
+ readme = "README.md"
8
+ classifiers = [
9
+ "Development Status :: 5 - Production/Stable",
10
+ "Intended Audience :: Developers",
11
+ "Operating System :: OS Independent",
12
+ "License :: OSI Approved :: MIT License",
13
+ "Programming Language :: Python :: 3.8",
14
+ "Programming Language :: Python :: 3.9",
15
+ "Programming Language :: Python :: 3.10",
16
+ "Programming Language :: Python :: 3.11",
17
+ "Programming Language :: Python :: Implementation :: PyPy",
18
+ ]
19
+ # packages = [{include = "onecache"}]
20
+
21
+ [tool.poetry.dependencies]
22
+ python = ">=3.8,<3.13"
23
+
24
+ [tool.poetry.group.test.dependencies]
25
+ flake8 = {version= "^7.1.0", python = ">=3.8.1"}
26
+ flake8-docstrings = "^1.7.0"
27
+ pytest = "^8.3.2"
28
+ pytest-asyncio = "^0.23.8"
29
+ pytest-sugar = "^1.0.0"
30
+ pytest-cov = "^5.0.0"
31
+
32
+
33
+ [tool.poetry.group.dev.dependencies]
34
+ autopep8 = {version="^2.3.1", python=">=3.8"}
35
+ sphinx = {version= "^8.0.2", python = ">=3.10"}
36
+ pylint = {version="^3.2.6", python=">=3.8"}
37
+
38
+ [build-system]
39
+ requires = ["poetry-core>=1.0.0"]
40
+ build-backend = "poetry.core.masonry.api"
@@ -1,2 +0,0 @@
1
- include README.md
2
- include *.txt
onecache-0.6.0/PKG-INFO DELETED
@@ -1,100 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: onecache
3
- Version: 0.6.0
4
- Summary: Python cache for sync and async code
5
- Author: Johanderson Mogollon
6
- Author-email: johander1822@gmail.com
7
- License: MIT
8
- Classifier: Development Status :: 5 - Production/Stable
9
- Classifier: Intended Audience :: Developers
10
- Classifier: Operating System :: OS Independent
11
- Classifier: License :: OSI Approved :: MIT License
12
- Classifier: Programming Language :: Python :: 3.6
13
- Classifier: Programming Language :: Python :: 3.7
14
- Classifier: Programming Language :: Python :: 3.8
15
- Classifier: Programming Language :: Python :: 3.9
16
- Classifier: Programming Language :: Python :: 3.10
17
- Classifier: Programming Language :: Python :: 3.11
18
- Classifier: Programming Language :: Python :: Implementation :: PyPy
19
- Description-Content-Type: text/markdown
20
- Provides-Extra: test
21
-
22
- [![Coverage Status](https://coveralls.io/repos/github/sonic182/onecache/badge.svg?branch=master)](https://coveralls.io/github/sonic182/onecache?branch=master)
23
- ![github status](https://github.com/sonic182/onecache/actions/workflows/python.yml/badge.svg)
24
- # OneCache
25
-
26
- Python cache for sync and async code.
27
-
28
- Cache uses LRU algoritm. Cache can optionally have TTL.
29
-
30
- Tested in python 3.7, 3.9, and pypy3.9 for windows, mac and linux (see github status badge), it should work in versions between them. It may work for python3.6
31
-
32
- # Usage
33
-
34
- ```python
35
- from onecache import CacheDecorator
36
- from onecache import AsyncCacheDecorator
37
-
38
-
39
- class Counter:
40
- def __init__(self, count=0):
41
- self.count = count
42
-
43
-
44
- @pytest.mark.asyncio
45
- async def test_async_cache_counter():
46
- """Test async cache, counter case."""
47
- counter = Counter()
48
-
49
- @AsyncCacheDecorator()
50
- async def mycoro(counter: Counter):
51
- counter.count += 1
52
- return counter.count
53
-
54
- assert 1 == (await mycoro(counter))
55
- assert 1 == (await mycoro(counter))
56
-
57
-
58
- def test_cache_counter():
59
- """Test async cache, counter case."""
60
- counter = Counter()
61
-
62
- @CacheDecorator()
63
- def sample(counter: Counter):
64
- counter.count += 1
65
- return counter.count
66
-
67
- assert 1 == (sample(counter))
68
- assert 1 == (sample(counter))
69
- ```
70
-
71
- Decorator classes supports the following arguments
72
-
73
- * **maxsize (int)**: Maximun number of items to be cached. default: 512
74
- * **ttl (int)**: time to expire in milliseconds, if None, it does not expire. default: None
75
- * **skip_args (bool)**: apply cache as the function doesn't have any arguments, default: False
76
- * **cache_class (class)**: Class to use for cache instance. default: LRUCache
77
- * **refresh_ttl (bool)**: if cache with ttl, This flag makes key expiration timestamp to be refresh per access. default: False
78
- * **thread_safe (bool)**: tell decorator to use thread safe lock. default=False
79
- * **max_mem_size (int)**: max mem size in bytes. Ceil for sum of cache values sizes. default=None which means no limit. For pypy this value is ignored as the objects can change by the JIT compilation.
80
-
81
- If num of records exceds maxsize, it drops the oldest.
82
-
83
-
84
- # Development
85
-
86
- Install packages with pip-tools:
87
- ```bash
88
- pip install pip-tools
89
- pip-compile
90
- pip-compile test-requirements.in
91
- pip-sync requirements.txt test-requirements.txt
92
- ```
93
-
94
- # Contribute
95
-
96
- 1. Fork
97
- 2. create a branch `feature/your_feature`
98
- 3. commit - push - pull request
99
-
100
- Thanks :)
@@ -1,88 +0,0 @@
1
- #
2
- # This file is autogenerated by pip-compile with Python 3.7
3
- # by the following command:
4
- #
5
- # pip-compile dev-requirements.in
6
- #
7
- alabaster==0.7.13
8
- # via sphinx
9
- astroid==2.15.6
10
- # via pylint
11
- autopep8==2.0.2
12
- # via -r dev-requirements.in
13
- babel==2.12.1
14
- # via sphinx
15
- certifi==2023.7.22
16
- # via requests
17
- charset-normalizer==3.2.0
18
- # via requests
19
- dill==0.3.7
20
- # via pylint
21
- docutils==0.19
22
- # via sphinx
23
- idna==3.4
24
- # via requests
25
- imagesize==1.4.1
26
- # via sphinx
27
- importlib-metadata==6.7.0
28
- # via sphinx
29
- isort==5.11.5
30
- # via pylint
31
- jinja2==3.1.2
32
- # via sphinx
33
- lazy-object-proxy==1.9.0
34
- # via astroid
35
- markupsafe==2.1.3
36
- # via jinja2
37
- mccabe==0.7.0
38
- # via pylint
39
- packaging==23.1
40
- # via sphinx
41
- platformdirs==3.10.0
42
- # via pylint
43
- pycodestyle==2.10.0
44
- # via autopep8
45
- pygments==2.16.1
46
- # via sphinx
47
- pylint==2.17.5
48
- # via -r dev-requirements.in
49
- pytz==2023.3
50
- # via babel
51
- requests==2.31.0
52
- # via sphinx
53
- snowballstemmer==2.2.0
54
- # via sphinx
55
- sphinx==5.3.0
56
- # via -r dev-requirements.in
57
- sphinxcontrib-applehelp==1.0.2
58
- # via sphinx
59
- sphinxcontrib-devhelp==1.0.2
60
- # via sphinx
61
- sphinxcontrib-htmlhelp==2.0.0
62
- # via sphinx
63
- sphinxcontrib-jsmath==1.0.1
64
- # via sphinx
65
- sphinxcontrib-qthelp==1.0.3
66
- # via sphinx
67
- sphinxcontrib-serializinghtml==1.1.5
68
- # via sphinx
69
- tomli==2.0.1
70
- # via
71
- # autopep8
72
- # pylint
73
- tomlkit==0.12.1
74
- # via pylint
75
- typed-ast==1.5.5
76
- # via astroid
77
- typing-extensions==4.7.1
78
- # via
79
- # astroid
80
- # importlib-metadata
81
- # platformdirs
82
- # pylint
83
- urllib3==2.0.4
84
- # via requests
85
- wrapt==1.15.0
86
- # via astroid
87
- zipp==3.15.0
88
- # via importlib-metadata
@@ -1,3 +0,0 @@
1
- import platform
2
-
3
- IS_PYPY = platform.python_implementation().lower().startswith("pypy")
@@ -1,15 +0,0 @@
1
- MANIFEST.in
2
- README.md
3
- dev-requirements.txt
4
- requirements.txt
5
- setup.cfg
6
- setup.py
7
- test-requirements.txt
8
- onecache/__init__.py
9
- onecache/cache_value.py
10
- onecache/utils.py
11
- onecache.egg-info/PKG-INFO
12
- onecache.egg-info/SOURCES.txt
13
- onecache.egg-info/dependency_links.txt
14
- onecache.egg-info/requires.txt
15
- onecache.egg-info/top_level.txt
@@ -1,30 +0,0 @@
1
-
2
- [test]
3
- certifi==2023.7.22
4
- charset-normalizer==3.2.0
5
- coverage[toml]==6.5.0
6
- coveralls==3.3.1
7
- docopt==0.6.2
8
- exceptiongroup==1.1.2
9
- flake8==5.0.4
10
- flake8-docstrings==1.7.0
11
- idna==3.4
12
- importlib-metadata==4.2.0
13
- iniconfig==2.0.0
14
- mccabe==0.7.0
15
- packaging==23.1
16
- pluggy==1.2.0
17
- pycodestyle==2.9.1
18
- pydocstyle==6.3.0
19
- pyflakes==2.5.0
20
- pytest==7.4.0
21
- pytest-asyncio==0.21.1
22
- pytest-cov==4.1.0
23
- pytest-sugar==0.9.7
24
- requests==2.31.0
25
- snowballstemmer==2.2.0
26
- termcolor==2.3.0
27
- tomli==2.0.1
28
- typing-extensions==4.7.1
29
- urllib3==2.0.4
30
- zipp==3.15.0
@@ -1 +0,0 @@
1
- onecache
@@ -1,6 +0,0 @@
1
- #
2
- # This file is autogenerated by pip-compile
3
- # To update, run:
4
- #
5
- # pip-compile --output-file requirements.txt requirements.in
6
- #
onecache-0.6.0/setup.cfg DELETED
@@ -1,19 +0,0 @@
1
- [metadata]
2
- description-file = Readme.md
3
-
4
- [aliases]
5
- test = pytest
6
-
7
- [tool:pytest]
8
- python_files = **/*.py
9
- testpaths = tests/
10
- python_functions = test_*
11
- addopts = --cov=onecache --cov-report term --cov-report html
12
-
13
- [coverage:run]
14
- relative_files = True
15
-
16
- [egg_info]
17
- tag_build =
18
- tag_date = 0
19
-
onecache-0.6.0/setup.py DELETED
@@ -1,44 +0,0 @@
1
- """Setup module."""
2
-
3
- from pkg_resources import parse_requirements
4
- from setuptools import setup
5
-
6
-
7
-
8
- def read_file(filename):
9
- """Read file correctly."""
10
- with open(filename) as _file:
11
- return _file.read().strip()
12
-
13
-
14
- def requirements(filename):
15
- """Parse requirements from file."""
16
- return [str(req) for req in parse_requirements(read_file(filename))]
17
-
18
-
19
- setup(
20
- name="onecache",
21
- version="0.6.0",
22
- description="Python cache for sync and async code",
23
- long_description=read_file("README.md"),
24
- long_description_content_type="text/markdown",
25
- author="Johanderson Mogollon",
26
- author_email="johander1822@gmail.com",
27
- license="MIT",
28
- packages=["onecache"],
29
- classifiers=[
30
- "Development Status :: 5 - Production/Stable",
31
- "Intended Audience :: Developers",
32
- "Operating System :: OS Independent",
33
- "License :: OSI Approved :: MIT License",
34
- "Programming Language :: Python :: 3.6",
35
- "Programming Language :: Python :: 3.7",
36
- "Programming Language :: Python :: 3.8",
37
- "Programming Language :: Python :: 3.9",
38
- "Programming Language :: Python :: 3.10",
39
- "Programming Language :: Python :: 3.11",
40
- "Programming Language :: Python :: Implementation :: PyPy",
41
- ],
42
- install_requires=requirements("./requirements.txt"),
43
- extras_require={"test": requirements("./test-requirements.txt")},
44
- )
@@ -1,80 +0,0 @@
1
- #
2
- # This file is autogenerated by pip-compile with Python 3.7
3
- # by the following command:
4
- #
5
- # pip-compile test-requirements.in
6
- #
7
- certifi==2023.7.22
8
- # via requests
9
- charset-normalizer==3.2.0
10
- # via requests
11
- coverage[toml]==6.5.0
12
- # via
13
- # coveralls
14
- # pytest-cov
15
- coveralls==3.3.1
16
- # via -r test-requirements.in
17
- docopt==0.6.2
18
- # via coveralls
19
- exceptiongroup==1.1.2
20
- # via pytest
21
- flake8==5.0.4
22
- # via
23
- # -r test-requirements.in
24
- # flake8-docstrings
25
- flake8-docstrings==1.7.0
26
- # via -r test-requirements.in
27
- idna==3.4
28
- # via requests
29
- importlib-metadata==4.2.0
30
- # via
31
- # flake8
32
- # pluggy
33
- # pydocstyle
34
- # pytest
35
- iniconfig==2.0.0
36
- # via pytest
37
- mccabe==0.7.0
38
- # via flake8
39
- packaging==23.1
40
- # via
41
- # pytest
42
- # pytest-sugar
43
- pluggy==1.2.0
44
- # via pytest
45
- pycodestyle==2.9.1
46
- # via flake8
47
- pydocstyle==6.3.0
48
- # via flake8-docstrings
49
- pyflakes==2.5.0
50
- # via flake8
51
- pytest==7.4.0
52
- # via
53
- # -r test-requirements.in
54
- # pytest-asyncio
55
- # pytest-cov
56
- # pytest-sugar
57
- pytest-asyncio==0.21.1
58
- # via -r test-requirements.in
59
- pytest-cov==4.1.0
60
- # via -r test-requirements.in
61
- pytest-sugar==0.9.7
62
- # via -r test-requirements.in
63
- requests==2.31.0
64
- # via coveralls
65
- snowballstemmer==2.2.0
66
- # via pydocstyle
67
- termcolor==2.3.0
68
- # via pytest-sugar
69
- tomli==2.0.1
70
- # via
71
- # coverage
72
- # pytest
73
- typing-extensions==4.7.1
74
- # via
75
- # importlib-metadata
76
- # pytest-asyncio
77
- urllib3==2.0.4
78
- # via requests
79
- zipp==3.15.0
80
- # via importlib-metadata