django-ormcache 1.2.1__tar.gz → 1.3__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.
- django_ormcache-1.3/PKG-INFO +54 -0
- django_ormcache-1.3/README.md +22 -0
- django_ormcache-1.3/django_ormcache.egg-info/PKG-INFO +54 -0
- {django-ormcache-1.2.1 → django_ormcache-1.3}/django_ormcache.egg-info/SOURCES.txt +8 -2
- django_ormcache-1.3/django_ormcache.egg-info/requires.txt +8 -0
- django_ormcache-1.3/django_ormcache.egg-info/top_level.txt +1 -0
- {django-ormcache-1.2.1 → django_ormcache-1.3}/ormcache/queryset.py +8 -3
- django_ormcache-1.3/pyproject.toml +3 -0
- {django-ormcache-1.2.1 → django_ormcache-1.3}/setup.cfg +3 -0
- {django-ormcache-1.2.1 → django_ormcache-1.3}/setup.py +14 -16
- django_ormcache-1.3/tests/test_decorators.py +28 -0
- django_ormcache-1.3/tests/test_managers.py +26 -0
- django_ormcache-1.3/tests/test_queryset.py +191 -0
- django_ormcache-1.3/tests/test_signals.py +59 -0
- django_ormcache-1.3/tests/test_utils.py +31 -0
- django-ormcache-1.2.1/PKG-INFO +0 -54
- django-ormcache-1.2.1/README.rst +0 -33
- django-ormcache-1.2.1/django_ormcache.egg-info/PKG-INFO +0 -54
- django-ormcache-1.2.1/django_ormcache.egg-info/requires.txt +0 -1
- django-ormcache-1.2.1/django_ormcache.egg-info/top_level.txt +0 -1
- {django-ormcache-1.2.1 → django_ormcache-1.3}/LICENSE +0 -0
- {django-ormcache-1.2.1 → django_ormcache-1.3}/MANIFEST.in +0 -0
- {django-ormcache-1.2.1 → django_ormcache-1.3}/django_ormcache.egg-info/dependency_links.txt +0 -0
- {django-ormcache-1.2.1 → django_ormcache-1.3}/ormcache/__init__.py +0 -0
- {django-ormcache-1.2.1 → django_ormcache-1.3}/ormcache/decorators.py +0 -0
- {django-ormcache-1.2.1 → django_ormcache-1.3}/ormcache/managers.py +0 -0
- {django-ormcache-1.2.1 → django_ormcache-1.3}/ormcache/models.py +0 -0
- {django-ormcache-1.2.1 → django_ormcache-1.3}/ormcache/signals.py +0 -0
- {django-ormcache-1.2.1 → django_ormcache-1.3}/ormcache/utils.py +0 -0
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: django-ormcache
|
|
3
|
+
Version: 1.3
|
|
4
|
+
Summary: ORM cache for Django
|
|
5
|
+
Home-page: https://github.com/educreations/django-ormcache
|
|
6
|
+
Author: Corey Farwell
|
|
7
|
+
Author-email: coreyf@rwell.org
|
|
8
|
+
Maintainer: Educreations Engineering
|
|
9
|
+
Maintainer-email: engineering@educreations.com
|
|
10
|
+
License: MIT
|
|
11
|
+
Project-URL: Homepage, https://github.com/educreations/django-ormcache
|
|
12
|
+
Project-URL: Issues, https://github.com/educreations/django-ormcache/issues
|
|
13
|
+
Project-URL: Changelog, https://github.com/educreations/django-ormcache/blob/master/CHANGES.md
|
|
14
|
+
Keywords: cache django
|
|
15
|
+
Classifier: Framework :: Django
|
|
16
|
+
Classifier: Intended Audience :: Developers
|
|
17
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
18
|
+
Classifier: Operating System :: OS Independent
|
|
19
|
+
Classifier: Programming Language :: Python
|
|
20
|
+
Classifier: Programming Language :: Python :: 3
|
|
21
|
+
Classifier: Topic :: Software Development
|
|
22
|
+
Requires-Python: >=3.7, <4
|
|
23
|
+
Description-Content-Type: text/markdown
|
|
24
|
+
License-File: LICENSE
|
|
25
|
+
Requires-Dist: Django<5.0,>=2.0
|
|
26
|
+
Requires-Dist: six
|
|
27
|
+
Provides-Extra: test
|
|
28
|
+
Requires-Dist: tox; extra == "test"
|
|
29
|
+
Requires-Dist: pytest; extra == "test"
|
|
30
|
+
Requires-Dist: pytest-django; extra == "test"
|
|
31
|
+
Requires-Dist: flake8; extra == "test"
|
|
32
|
+
|
|
33
|
+
# Django ORMCache
|
|
34
|
+
|
|
35
|
+
A cache manager mixin that provides some caching of objects for the ORM.
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
# Installation / Setup / Usage
|
|
39
|
+
|
|
40
|
+
TODO
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
# Testing
|
|
44
|
+
|
|
45
|
+
Run the tests with:
|
|
46
|
+
|
|
47
|
+
```
|
|
48
|
+
pip install -e .[tests]
|
|
49
|
+
tox
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
# License
|
|
53
|
+
|
|
54
|
+
Copyright © 2024, Educreations, Inc under the [MIT](LICENSE).
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# Django ORMCache
|
|
2
|
+
|
|
3
|
+
A cache manager mixin that provides some caching of objects for the ORM.
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
# Installation / Setup / Usage
|
|
7
|
+
|
|
8
|
+
TODO
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
# Testing
|
|
12
|
+
|
|
13
|
+
Run the tests with:
|
|
14
|
+
|
|
15
|
+
```
|
|
16
|
+
pip install -e .[tests]
|
|
17
|
+
tox
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
# License
|
|
21
|
+
|
|
22
|
+
Copyright © 2024, Educreations, Inc under the [MIT](LICENSE).
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: django-ormcache
|
|
3
|
+
Version: 1.3
|
|
4
|
+
Summary: ORM cache for Django
|
|
5
|
+
Home-page: https://github.com/educreations/django-ormcache
|
|
6
|
+
Author: Corey Farwell
|
|
7
|
+
Author-email: coreyf@rwell.org
|
|
8
|
+
Maintainer: Educreations Engineering
|
|
9
|
+
Maintainer-email: engineering@educreations.com
|
|
10
|
+
License: MIT
|
|
11
|
+
Project-URL: Homepage, https://github.com/educreations/django-ormcache
|
|
12
|
+
Project-URL: Issues, https://github.com/educreations/django-ormcache/issues
|
|
13
|
+
Project-URL: Changelog, https://github.com/educreations/django-ormcache/blob/master/CHANGES.md
|
|
14
|
+
Keywords: cache django
|
|
15
|
+
Classifier: Framework :: Django
|
|
16
|
+
Classifier: Intended Audience :: Developers
|
|
17
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
18
|
+
Classifier: Operating System :: OS Independent
|
|
19
|
+
Classifier: Programming Language :: Python
|
|
20
|
+
Classifier: Programming Language :: Python :: 3
|
|
21
|
+
Classifier: Topic :: Software Development
|
|
22
|
+
Requires-Python: >=3.7, <4
|
|
23
|
+
Description-Content-Type: text/markdown
|
|
24
|
+
License-File: LICENSE
|
|
25
|
+
Requires-Dist: Django<5.0,>=2.0
|
|
26
|
+
Requires-Dist: six
|
|
27
|
+
Provides-Extra: test
|
|
28
|
+
Requires-Dist: tox; extra == "test"
|
|
29
|
+
Requires-Dist: pytest; extra == "test"
|
|
30
|
+
Requires-Dist: pytest-django; extra == "test"
|
|
31
|
+
Requires-Dist: flake8; extra == "test"
|
|
32
|
+
|
|
33
|
+
# Django ORMCache
|
|
34
|
+
|
|
35
|
+
A cache manager mixin that provides some caching of objects for the ORM.
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
# Installation / Setup / Usage
|
|
39
|
+
|
|
40
|
+
TODO
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
# Testing
|
|
44
|
+
|
|
45
|
+
Run the tests with:
|
|
46
|
+
|
|
47
|
+
```
|
|
48
|
+
pip install -e .[tests]
|
|
49
|
+
tox
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
# License
|
|
53
|
+
|
|
54
|
+
Copyright © 2024, Educreations, Inc under the [MIT](LICENSE).
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
LICENSE
|
|
2
2
|
MANIFEST.in
|
|
3
|
-
README.
|
|
3
|
+
README.md
|
|
4
|
+
pyproject.toml
|
|
4
5
|
setup.cfg
|
|
5
6
|
setup.py
|
|
6
7
|
django_ormcache.egg-info/PKG-INFO
|
|
@@ -14,4 +15,9 @@ ormcache/managers.py
|
|
|
14
15
|
ormcache/models.py
|
|
15
16
|
ormcache/queryset.py
|
|
16
17
|
ormcache/signals.py
|
|
17
|
-
ormcache/utils.py
|
|
18
|
+
ormcache/utils.py
|
|
19
|
+
tests/test_decorators.py
|
|
20
|
+
tests/test_managers.py
|
|
21
|
+
tests/test_queryset.py
|
|
22
|
+
tests/test_signals.py
|
|
23
|
+
tests/test_utils.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
import
|
|
1
|
+
from __future__ import unicode_literals
|
|
2
|
+
|
|
3
|
+
try:
|
|
4
|
+
from collections.abc import Iterable
|
|
5
|
+
except ImportError:
|
|
6
|
+
from collections import Iterable
|
|
7
|
+
|
|
2
8
|
import logging
|
|
3
9
|
|
|
4
10
|
import django
|
|
@@ -18,7 +24,6 @@ log = logging.getLogger(__name__)
|
|
|
18
24
|
|
|
19
25
|
|
|
20
26
|
class CachedQuerySet(QuerySet):
|
|
21
|
-
|
|
22
27
|
__MAXIMUM_CACHE_KEY_LENGTH = 250
|
|
23
28
|
__CACHE_FOREVER = 2592000 # http://ur1.ca/egyvu
|
|
24
29
|
|
|
@@ -88,7 +93,7 @@ class CachedQuerySet(QuerySet):
|
|
|
88
93
|
return item
|
|
89
94
|
|
|
90
95
|
def from_ids(self, ids, lookup="pk__in"):
|
|
91
|
-
assert isinstance(ids,
|
|
96
|
+
assert isinstance(ids, Iterable)
|
|
92
97
|
|
|
93
98
|
cache_keys = [self.cache_key(id_) for id_ in ids]
|
|
94
99
|
|
|
@@ -1,21 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
from setuptools import setup, find_packages
|
|
2
2
|
|
|
3
|
-
import os
|
|
4
|
-
import sys
|
|
5
3
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
if sys.argv[-1] == "publish":
|
|
10
|
-
os.system("python setup.py register sdist bdist_wheel upload")
|
|
11
|
-
sys.exit()
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
readme_text = open("README.rst", "r").read()
|
|
4
|
+
readme_text = open("README.md", "r").read()
|
|
15
5
|
|
|
16
6
|
setup(
|
|
17
7
|
name="django-ormcache",
|
|
18
|
-
version="1.
|
|
8
|
+
version="1.3",
|
|
19
9
|
description="ORM cache for Django",
|
|
20
10
|
license="MIT",
|
|
21
11
|
keywords="cache django",
|
|
@@ -25,17 +15,25 @@ setup(
|
|
|
25
15
|
maintainer_email="engineering@educreations.com",
|
|
26
16
|
url="https://github.com/educreations/django-ormcache",
|
|
27
17
|
long_description=readme_text,
|
|
28
|
-
|
|
18
|
+
long_description_content_type="text/markdown",
|
|
19
|
+
packages=find_packages(where="ormcache"),
|
|
29
20
|
package_dir={"ormcache": "ormcache"},
|
|
30
|
-
|
|
21
|
+
python_requires=">=3.7, <4",
|
|
22
|
+
install_requires=["Django>=2.0,<5.0", "six"],
|
|
31
23
|
classifiers=[
|
|
32
24
|
"Framework :: Django",
|
|
33
25
|
"Intended Audience :: Developers",
|
|
34
26
|
"License :: OSI Approved :: MIT License",
|
|
35
27
|
"Operating System :: OS Independent",
|
|
36
28
|
"Programming Language :: Python",
|
|
37
|
-
"Programming Language :: Python :: 2.7",
|
|
38
29
|
"Programming Language :: Python :: 3",
|
|
39
30
|
"Topic :: Software Development",
|
|
40
31
|
],
|
|
32
|
+
extras_require={"test": ["tox", "pytest", "pytest-django", "flake8"]},
|
|
33
|
+
tests_require=["django-ormcache[test]"],
|
|
34
|
+
project_urls={
|
|
35
|
+
"Homepage": "https://github.com/educreations/django-ormcache",
|
|
36
|
+
"Issues": "https://github.com/educreations/django-ormcache/issues",
|
|
37
|
+
"Changelog": "https://github.com/educreations/django-ormcache/blob/master/CHANGES.md",
|
|
38
|
+
},
|
|
41
39
|
)
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
from django.core.cache import cache
|
|
2
|
+
from django.test import SimpleTestCase
|
|
3
|
+
|
|
4
|
+
from ormcache.decorators import cache_result
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class DecoratorsCacheTestCase(SimpleTestCase):
|
|
8
|
+
def test_cache_result(self):
|
|
9
|
+
call_counts = [0]
|
|
10
|
+
value = {"hello": "world"}
|
|
11
|
+
|
|
12
|
+
@cache_result()
|
|
13
|
+
def random_function():
|
|
14
|
+
call_counts[0] += 1
|
|
15
|
+
return value
|
|
16
|
+
|
|
17
|
+
result = random_function()
|
|
18
|
+
self.assertTrue(value, result)
|
|
19
|
+
self.assertEqual(1, call_counts[0])
|
|
20
|
+
|
|
21
|
+
result = random_function()
|
|
22
|
+
self.assertTrue(value, result)
|
|
23
|
+
self.assertEqual(1, call_counts[0])
|
|
24
|
+
|
|
25
|
+
cache.clear()
|
|
26
|
+
result = random_function()
|
|
27
|
+
self.assertTrue(value, result)
|
|
28
|
+
self.assertEqual(2, call_counts[0])
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
from django.test import SimpleTestCase
|
|
2
|
+
|
|
3
|
+
from tests.testapp.models import CachedDummyModel, UncachedDummyModel
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class BaseManagerCacheTestCase(SimpleTestCase):
|
|
7
|
+
def test_cache_key_on_uncached(self):
|
|
8
|
+
with self.assertRaises(RuntimeError):
|
|
9
|
+
UncachedDummyModel.objects.cache_key(1)
|
|
10
|
+
|
|
11
|
+
def test_invalidate_on_uncached(self):
|
|
12
|
+
with self.assertRaises(RuntimeError):
|
|
13
|
+
UncachedDummyModel.objects.invalidate(1)
|
|
14
|
+
|
|
15
|
+
def test_cache_key_on_cached(self):
|
|
16
|
+
try:
|
|
17
|
+
cache_key = CachedDummyModel.objects.cache_key(1)
|
|
18
|
+
except RuntimeError:
|
|
19
|
+
self.fail("Should not have raised exception")
|
|
20
|
+
self.assertIsNotNone(cache_key)
|
|
21
|
+
|
|
22
|
+
def test_invalidate_on_cached(self):
|
|
23
|
+
try:
|
|
24
|
+
CachedDummyModel.objects.invalidate(1)
|
|
25
|
+
except RuntimeError:
|
|
26
|
+
self.fail("Should not have raised exception")
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import django
|
|
2
|
+
from django.core.cache import cache
|
|
3
|
+
from django.test import TestCase
|
|
4
|
+
|
|
5
|
+
from tests.testapp.models import (
|
|
6
|
+
CachedDummyModel,
|
|
7
|
+
OtherCachedDummyModel,
|
|
8
|
+
UncachedDummyModel,
|
|
9
|
+
)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class UncachedModelQuerySetTestCase(TestCase):
|
|
13
|
+
def setUp(self):
|
|
14
|
+
self.instance = UncachedDummyModel.objects.create()
|
|
15
|
+
cache.clear()
|
|
16
|
+
|
|
17
|
+
def test_no_cache(self):
|
|
18
|
+
with self.assertNumQueries(1):
|
|
19
|
+
UncachedDummyModel.objects.get(pk=self.instance.pk)
|
|
20
|
+
|
|
21
|
+
# Should still be one query
|
|
22
|
+
with self.assertNumQueries(1):
|
|
23
|
+
UncachedDummyModel.objects.get(pk=self.instance.pk)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class CachedQuerySetTestCase(TestCase):
|
|
27
|
+
def setUp(self):
|
|
28
|
+
self.instance1 = CachedDummyModel.objects.create()
|
|
29
|
+
self.instance2 = CachedDummyModel.objects.create()
|
|
30
|
+
self.pks = [self.instance1.pk, self.instance2.pk]
|
|
31
|
+
cache.clear()
|
|
32
|
+
|
|
33
|
+
def test_filter_get_nocache(self):
|
|
34
|
+
# Get the cache key for an instance, make sure it doesn't exist
|
|
35
|
+
cache_key = CachedDummyModel.objects.cache_key(self.instance1.pk)
|
|
36
|
+
self.assertIsNone(cache.get(cache_key))
|
|
37
|
+
|
|
38
|
+
# Use .get() after .filter() with no args, should set cache
|
|
39
|
+
with self.assertNumQueries(1):
|
|
40
|
+
CachedDummyModel.objects.filter().get(pk=self.instance1.pk)
|
|
41
|
+
CachedDummyModel.objects.filter().get(pk=self.instance1.pk)
|
|
42
|
+
self.assertIsNotNone(cache.get(cache_key))
|
|
43
|
+
cache.clear()
|
|
44
|
+
|
|
45
|
+
# Use .get() after .filter(...), should not set cache
|
|
46
|
+
with self.assertNumQueries(2):
|
|
47
|
+
CachedDummyModel.objects.filter(pk__gt=0).get(pk=self.instance1.pk)
|
|
48
|
+
CachedDummyModel.objects.filter(pk__gt=0).get(pk=self.instance1.pk)
|
|
49
|
+
self.assertIsNone(cache.get(cache_key))
|
|
50
|
+
|
|
51
|
+
# Use .get() after .filter(pk=), should set cache
|
|
52
|
+
if django.VERSION >= (1, 7):
|
|
53
|
+
with self.assertNumQueries(1):
|
|
54
|
+
CachedDummyModel.objects.filter(pk=self.instance1.pk).get()
|
|
55
|
+
CachedDummyModel.objects.filter(pk=self.instance1.pk).get()
|
|
56
|
+
self.assertIsNotNone(cache.get(cache_key))
|
|
57
|
+
cache.clear()
|
|
58
|
+
|
|
59
|
+
# Use .get() with another getter and modifier
|
|
60
|
+
with self.assertNumQueries(2):
|
|
61
|
+
kwargs = {"pk__gte": self.instance1.pk, "pk__lte": self.instance1.pk}
|
|
62
|
+
CachedDummyModel.objects.get(**kwargs)
|
|
63
|
+
CachedDummyModel.objects.get(**kwargs)
|
|
64
|
+
self.assertIsNone(cache.get(cache_key))
|
|
65
|
+
|
|
66
|
+
# Use .get() with various pk getters, and cache should be set
|
|
67
|
+
for pk_id in ("pk", "id"):
|
|
68
|
+
for modifier in ("", "__exact"):
|
|
69
|
+
with self.assertNumQueries(1):
|
|
70
|
+
kwargs = {"{}{}".format(pk_id, modifier): self.instance1.pk}
|
|
71
|
+
CachedDummyModel.objects.get(**kwargs)
|
|
72
|
+
CachedDummyModel.objects.get(**kwargs)
|
|
73
|
+
self.assertIsNotNone(cache.get(cache_key))
|
|
74
|
+
cache.clear()
|
|
75
|
+
|
|
76
|
+
def test_from_ids_cache(self):
|
|
77
|
+
with self.assertNumQueries(1):
|
|
78
|
+
instances = CachedDummyModel.objects.from_ids(self.pks)
|
|
79
|
+
self.assertEqual(2, len(instances))
|
|
80
|
+
self.assertIsInstance(instances, list)
|
|
81
|
+
|
|
82
|
+
with self.assertNumQueries(0):
|
|
83
|
+
instances = CachedDummyModel.objects.from_ids(self.pks)
|
|
84
|
+
self.assertEqual(2, len(instances))
|
|
85
|
+
self.assertIsInstance(instances, list)
|
|
86
|
+
|
|
87
|
+
def test_from_ids_invalid_pk(self):
|
|
88
|
+
self.pks.append(self.instance1.pk + self.instance2.pk)
|
|
89
|
+
|
|
90
|
+
with self.assertNumQueries(1):
|
|
91
|
+
instances = CachedDummyModel.objects.from_ids(self.pks)
|
|
92
|
+
self.assertEqual(2, len(instances))
|
|
93
|
+
self.assertIsInstance(instances, list)
|
|
94
|
+
|
|
95
|
+
with self.assertNumQueries(1):
|
|
96
|
+
instances = CachedDummyModel.objects.from_ids(self.pks)
|
|
97
|
+
self.assertIsInstance(instances, list)
|
|
98
|
+
|
|
99
|
+
def test_from_ids_invalidation(self):
|
|
100
|
+
with self.assertNumQueries(1):
|
|
101
|
+
instances = CachedDummyModel.objects.from_ids(self.pks)
|
|
102
|
+
self.assertEqual(2, len(instances))
|
|
103
|
+
self.assertIsInstance(instances, list)
|
|
104
|
+
|
|
105
|
+
CachedDummyModel.objects.invalidate(self.instance1.pk)
|
|
106
|
+
|
|
107
|
+
with self.assertNumQueries(1):
|
|
108
|
+
instances = CachedDummyModel.objects.from_ids(self.pks)
|
|
109
|
+
self.assertEqual(2, len(instances))
|
|
110
|
+
self.assertIsInstance(instances, list)
|
|
111
|
+
|
|
112
|
+
def test_one_deferred_field(self):
|
|
113
|
+
# This should not cache lesson since it contains a deferred field
|
|
114
|
+
CachedDummyModel.objects.defer("title").get(pk=self.instance1.pk)
|
|
115
|
+
|
|
116
|
+
with self.assertNumQueries(1):
|
|
117
|
+
summary = CachedDummyModel.objects.get(pk=self.instance1.pk).summary
|
|
118
|
+
|
|
119
|
+
self.assertEqual(self.instance1.summary, summary)
|
|
120
|
+
|
|
121
|
+
def test_all_deferred_fields(self):
|
|
122
|
+
# This should not cache lesson since it contains deferred fields
|
|
123
|
+
CachedDummyModel.objects.only().get(pk=self.instance1.pk)
|
|
124
|
+
|
|
125
|
+
with self.assertNumQueries(1):
|
|
126
|
+
title = CachedDummyModel.objects.get(pk=self.instance1.pk).title
|
|
127
|
+
|
|
128
|
+
self.assertEqual(self.instance1.title, title)
|
|
129
|
+
cache.clear()
|
|
130
|
+
|
|
131
|
+
def test_invalidated_after_delete(self):
|
|
132
|
+
# Get the cache key for an instance, make sure it doesn't exist
|
|
133
|
+
cache_key = CachedDummyModel.objects.cache_key(self.instance1.pk)
|
|
134
|
+
self.assertIsNone(cache.get(cache_key))
|
|
135
|
+
|
|
136
|
+
instance_pk = self.instance1.pk
|
|
137
|
+
|
|
138
|
+
with self.assertNumQueries(1):
|
|
139
|
+
CachedDummyModel.objects.get(pk=self.instance1.pk)
|
|
140
|
+
|
|
141
|
+
# Delete the instance
|
|
142
|
+
with self.assertNumQueries(1):
|
|
143
|
+
self.instance1.delete()
|
|
144
|
+
|
|
145
|
+
# Nothing should be in the cache
|
|
146
|
+
self.assertIsNone(cache.get(cache_key))
|
|
147
|
+
|
|
148
|
+
# Fetching should raise
|
|
149
|
+
with self.assertRaises(CachedDummyModel.DoesNotExist):
|
|
150
|
+
CachedDummyModel.objects.get(pk=instance_pk)
|
|
151
|
+
|
|
152
|
+
# Make sure that invalidation does not raise an exception
|
|
153
|
+
CachedDummyModel.objects.invalidate(pk=instance_pk, recache=True)
|
|
154
|
+
self.assertIsNone(cache.get(cache_key))
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
class CachedQuerySetRelatedTestCase(TestCase):
|
|
158
|
+
def setUp(self):
|
|
159
|
+
self.other_dummy = OtherCachedDummyModel.objects.create()
|
|
160
|
+
self.dummy = CachedDummyModel.objects.create()
|
|
161
|
+
self.dummy.related = self.other_dummy
|
|
162
|
+
self.dummy.save()
|
|
163
|
+
cache.clear()
|
|
164
|
+
|
|
165
|
+
def test_no_related_cache(self):
|
|
166
|
+
with self.assertNumQueries(2):
|
|
167
|
+
instance = OtherCachedDummyModel.objects.get(pk=self.other_dummy.pk)
|
|
168
|
+
related_pks = [
|
|
169
|
+
related.pk for related in instance.cacheddummymodel_set.all()
|
|
170
|
+
]
|
|
171
|
+
self.assertIn(self.dummy.pk, related_pks)
|
|
172
|
+
|
|
173
|
+
with self.assertNumQueries(1):
|
|
174
|
+
list(
|
|
175
|
+
OtherCachedDummyModel.objects.get(
|
|
176
|
+
pk=self.other_dummy.pk
|
|
177
|
+
).cacheddummymodel_set.all()
|
|
178
|
+
)
|
|
179
|
+
|
|
180
|
+
def test_related_cache(self):
|
|
181
|
+
with self.assertNumQueries(2):
|
|
182
|
+
self.assertEqual(
|
|
183
|
+
self.other_dummy.pk,
|
|
184
|
+
CachedDummyModel.objects.get(pk=self.dummy.pk).related.pk,
|
|
185
|
+
)
|
|
186
|
+
|
|
187
|
+
with self.assertNumQueries(0):
|
|
188
|
+
self.assertEqual(
|
|
189
|
+
self.other_dummy.pk,
|
|
190
|
+
CachedDummyModel.objects.get(pk=self.dummy.pk).related.pk,
|
|
191
|
+
)
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
from django.core.cache import cache
|
|
2
|
+
from django.test import TestCase
|
|
3
|
+
|
|
4
|
+
from ormcache.signals import cache_hit, cache_missed, cache_invalidated
|
|
5
|
+
from tests.testapp.models import CachedDummyModel
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class SignalsTestCase(TestCase):
|
|
9
|
+
def setUp(self):
|
|
10
|
+
self.call_count = 0
|
|
11
|
+
self.instance_pk = CachedDummyModel.objects.create().pk
|
|
12
|
+
cache.clear()
|
|
13
|
+
|
|
14
|
+
def _signal_receiver(self):
|
|
15
|
+
def inner(*args, **kwargs):
|
|
16
|
+
self.call_count += 1
|
|
17
|
+
|
|
18
|
+
return inner
|
|
19
|
+
|
|
20
|
+
def test_cache_hit_signal(self):
|
|
21
|
+
cache_hit.connect(self._signal_receiver(), weak=False)
|
|
22
|
+
|
|
23
|
+
# Cache miss
|
|
24
|
+
CachedDummyModel.objects.get(pk=self.instance_pk)
|
|
25
|
+
self.assertEqual(0, self.call_count)
|
|
26
|
+
|
|
27
|
+
# Cache hit
|
|
28
|
+
CachedDummyModel.objects.get(pk=self.instance_pk)
|
|
29
|
+
self.assertEqual(1, self.call_count)
|
|
30
|
+
|
|
31
|
+
def test_cache_missed_signal(self):
|
|
32
|
+
cache_missed.connect(self._signal_receiver(), weak=False)
|
|
33
|
+
|
|
34
|
+
# Cache miss
|
|
35
|
+
CachedDummyModel.objects.get(pk=self.instance_pk)
|
|
36
|
+
self.assertEqual(1, self.call_count)
|
|
37
|
+
|
|
38
|
+
def test_cache_invalidated_signal(self):
|
|
39
|
+
cache_invalidated.connect(self._signal_receiver(), weak=False)
|
|
40
|
+
|
|
41
|
+
# Cache miss
|
|
42
|
+
instance = CachedDummyModel.objects.get(pk=self.instance_pk)
|
|
43
|
+
self.assertEqual(0, self.call_count)
|
|
44
|
+
|
|
45
|
+
# Save the object
|
|
46
|
+
instance.title = "hello"
|
|
47
|
+
instance.save() # invalidate
|
|
48
|
+
self.assertEqual(1, self.call_count)
|
|
49
|
+
|
|
50
|
+
def test_cache_invalidate_on_delete_signal(self):
|
|
51
|
+
cache_invalidated.connect(self._signal_receiver(), weak=False)
|
|
52
|
+
|
|
53
|
+
# Cache miss
|
|
54
|
+
instance = CachedDummyModel.objects.get(pk=self.instance_pk)
|
|
55
|
+
self.assertEqual(0, self.call_count)
|
|
56
|
+
|
|
57
|
+
# Delete the object
|
|
58
|
+
instance.delete()
|
|
59
|
+
self.assertEqual(1, self.call_count)
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
from django.core.cache import cache
|
|
2
|
+
from django import test
|
|
3
|
+
|
|
4
|
+
from tests.testapp.models import (
|
|
5
|
+
CachedDummyModel,
|
|
6
|
+
OtherCachedDummyModel,
|
|
7
|
+
)
|
|
8
|
+
from ormcache.utils import attach_foreignkey
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class AttachForeignkeyTestCase(test.TestCase):
|
|
12
|
+
def setUp(self):
|
|
13
|
+
self.related_instance = OtherCachedDummyModel.objects.create()
|
|
14
|
+
self.instance = CachedDummyModel.objects.create(related=self.related_instance)
|
|
15
|
+
|
|
16
|
+
cache.clear()
|
|
17
|
+
|
|
18
|
+
def test_attach_foreignkey(self):
|
|
19
|
+
instances = list(CachedDummyModel.objects.all())
|
|
20
|
+
|
|
21
|
+
cache_key = OtherCachedDummyModel.objects.cache_key(self.related_instance.pk)
|
|
22
|
+
|
|
23
|
+
self.assertFalse(cache_key in cache)
|
|
24
|
+
|
|
25
|
+
with self.assertNumQueries(1):
|
|
26
|
+
attach_foreignkey(instances, CachedDummyModel.related)
|
|
27
|
+
|
|
28
|
+
self.assertTrue(cache_key in cache)
|
|
29
|
+
|
|
30
|
+
with self.assertNumQueries(0):
|
|
31
|
+
attach_foreignkey(instances, CachedDummyModel.related)
|
django-ormcache-1.2.1/PKG-INFO
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 1.2
|
|
2
|
-
Name: django-ormcache
|
|
3
|
-
Version: 1.2.1
|
|
4
|
-
Summary: ORM cache for Django
|
|
5
|
-
Home-page: https://github.com/educreations/django-ormcache
|
|
6
|
-
Author: Corey Farwell
|
|
7
|
-
Author-email: coreyf@rwell.org
|
|
8
|
-
Maintainer: Educreations Engineering
|
|
9
|
-
Maintainer-email: engineering@educreations.com
|
|
10
|
-
License: MIT
|
|
11
|
-
Description: Django ORMCache
|
|
12
|
-
===============
|
|
13
|
-
|
|
14
|
-
.. image:: https://travis-ci.org/educreations/django-ormcache.svg?branch=master
|
|
15
|
-
:target: https://travis-ci.org/educreations/django-ormcache
|
|
16
|
-
|
|
17
|
-
.. image:: https://coveralls.io/repos/github/educreations/django-ormcache/badge.svg?branch=master
|
|
18
|
-
:target: https://coveralls.io/github/educreations/django-ormcache?branch=master
|
|
19
|
-
|
|
20
|
-
A cache manager mixin that provides some caching of objects for the ORM.
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
Installation / Setup / Usage
|
|
24
|
-
----------------------------
|
|
25
|
-
|
|
26
|
-
TODO
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
Testing
|
|
30
|
-
-------
|
|
31
|
-
|
|
32
|
-
Run the tests with:
|
|
33
|
-
|
|
34
|
-
.. code:: bash
|
|
35
|
-
|
|
36
|
-
pip install -r requirements.txt
|
|
37
|
-
python runtests.py
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
License
|
|
41
|
-
-------
|
|
42
|
-
|
|
43
|
-
Copyright © 2017, Educreations, Inc under the `MIT <LICENSE>`_.
|
|
44
|
-
|
|
45
|
-
Keywords: cache django
|
|
46
|
-
Platform: UNKNOWN
|
|
47
|
-
Classifier: Framework :: Django
|
|
48
|
-
Classifier: Intended Audience :: Developers
|
|
49
|
-
Classifier: License :: OSI Approved :: MIT License
|
|
50
|
-
Classifier: Operating System :: OS Independent
|
|
51
|
-
Classifier: Programming Language :: Python
|
|
52
|
-
Classifier: Programming Language :: Python :: 2.7
|
|
53
|
-
Classifier: Programming Language :: Python :: 3
|
|
54
|
-
Classifier: Topic :: Software Development
|
django-ormcache-1.2.1/README.rst
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
Django ORMCache
|
|
2
|
-
===============
|
|
3
|
-
|
|
4
|
-
.. image:: https://travis-ci.org/educreations/django-ormcache.svg?branch=master
|
|
5
|
-
:target: https://travis-ci.org/educreations/django-ormcache
|
|
6
|
-
|
|
7
|
-
.. image:: https://coveralls.io/repos/github/educreations/django-ormcache/badge.svg?branch=master
|
|
8
|
-
:target: https://coveralls.io/github/educreations/django-ormcache?branch=master
|
|
9
|
-
|
|
10
|
-
A cache manager mixin that provides some caching of objects for the ORM.
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
Installation / Setup / Usage
|
|
14
|
-
----------------------------
|
|
15
|
-
|
|
16
|
-
TODO
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
Testing
|
|
20
|
-
-------
|
|
21
|
-
|
|
22
|
-
Run the tests with:
|
|
23
|
-
|
|
24
|
-
.. code:: bash
|
|
25
|
-
|
|
26
|
-
pip install -r requirements.txt
|
|
27
|
-
python runtests.py
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
License
|
|
31
|
-
-------
|
|
32
|
-
|
|
33
|
-
Copyright © 2017, Educreations, Inc under the `MIT <LICENSE>`_.
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 1.2
|
|
2
|
-
Name: django-ormcache
|
|
3
|
-
Version: 1.2.1
|
|
4
|
-
Summary: ORM cache for Django
|
|
5
|
-
Home-page: https://github.com/educreations/django-ormcache
|
|
6
|
-
Author: Corey Farwell
|
|
7
|
-
Author-email: coreyf@rwell.org
|
|
8
|
-
Maintainer: Educreations Engineering
|
|
9
|
-
Maintainer-email: engineering@educreations.com
|
|
10
|
-
License: MIT
|
|
11
|
-
Description: Django ORMCache
|
|
12
|
-
===============
|
|
13
|
-
|
|
14
|
-
.. image:: https://travis-ci.org/educreations/django-ormcache.svg?branch=master
|
|
15
|
-
:target: https://travis-ci.org/educreations/django-ormcache
|
|
16
|
-
|
|
17
|
-
.. image:: https://coveralls.io/repos/github/educreations/django-ormcache/badge.svg?branch=master
|
|
18
|
-
:target: https://coveralls.io/github/educreations/django-ormcache?branch=master
|
|
19
|
-
|
|
20
|
-
A cache manager mixin that provides some caching of objects for the ORM.
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
Installation / Setup / Usage
|
|
24
|
-
----------------------------
|
|
25
|
-
|
|
26
|
-
TODO
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
Testing
|
|
30
|
-
-------
|
|
31
|
-
|
|
32
|
-
Run the tests with:
|
|
33
|
-
|
|
34
|
-
.. code:: bash
|
|
35
|
-
|
|
36
|
-
pip install -r requirements.txt
|
|
37
|
-
python runtests.py
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
License
|
|
41
|
-
-------
|
|
42
|
-
|
|
43
|
-
Copyright © 2017, Educreations, Inc under the `MIT <LICENSE>`_.
|
|
44
|
-
|
|
45
|
-
Keywords: cache django
|
|
46
|
-
Platform: UNKNOWN
|
|
47
|
-
Classifier: Framework :: Django
|
|
48
|
-
Classifier: Intended Audience :: Developers
|
|
49
|
-
Classifier: License :: OSI Approved :: MIT License
|
|
50
|
-
Classifier: Operating System :: OS Independent
|
|
51
|
-
Classifier: Programming Language :: Python
|
|
52
|
-
Classifier: Programming Language :: Python :: 2.7
|
|
53
|
-
Classifier: Programming Language :: Python :: 3
|
|
54
|
-
Classifier: Topic :: Software Development
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
Django<4.0,>=1.9
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
ormcache
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|