django-cache-cleaner 0.1.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.
- django_cache_cleaner-0.1.0/LICENSE.txt +21 -0
- django_cache_cleaner-0.1.0/MANIFEST.in +4 -0
- django_cache_cleaner-0.1.0/PKG-INFO +168 -0
- django_cache_cleaner-0.1.0/README.md +111 -0
- django_cache_cleaner-0.1.0/cache_cleaner/__init__.py +0 -0
- django_cache_cleaner-0.1.0/cache_cleaner/admin.py +37 -0
- django_cache_cleaner-0.1.0/cache_cleaner/apps.py +8 -0
- django_cache_cleaner-0.1.0/cache_cleaner/locale/en/LC_MESSAGES/django.mo +0 -0
- django_cache_cleaner-0.1.0/cache_cleaner/locale/en/LC_MESSAGES/django.po +42 -0
- django_cache_cleaner-0.1.0/cache_cleaner/locale/it/LC_MESSAGES/django.mo +0 -0
- django_cache_cleaner-0.1.0/cache_cleaner/locale/it/LC_MESSAGES/django.po +42 -0
- django_cache_cleaner-0.1.0/cache_cleaner/management/__init__.py +0 -0
- django_cache_cleaner-0.1.0/cache_cleaner/management/commands/__init__.py +0 -0
- django_cache_cleaner-0.1.0/cache_cleaner/management/commands/clear_cache.py +76 -0
- django_cache_cleaner-0.1.0/cache_cleaner/metadata.py +10 -0
- django_cache_cleaner-0.1.0/cache_cleaner/migrations/0001_initial.py +29 -0
- django_cache_cleaner-0.1.0/cache_cleaner/migrations/__init__.py +0 -0
- django_cache_cleaner-0.1.0/cache_cleaner/models.py +35 -0
- django_cache_cleaner-0.1.0/django_cache_cleaner.egg-info/PKG-INFO +168 -0
- django_cache_cleaner-0.1.0/django_cache_cleaner.egg-info/SOURCES.txt +27 -0
- django_cache_cleaner-0.1.0/django_cache_cleaner.egg-info/dependency_links.txt +1 -0
- django_cache_cleaner-0.1.0/django_cache_cleaner.egg-info/top_level.txt +1 -0
- django_cache_cleaner-0.1.0/pyproject.toml +99 -0
- django_cache_cleaner-0.1.0/setup.cfg +4 -0
- django_cache_cleaner-0.1.0/setup.py +4 -0
- django_cache_cleaner-0.1.0/tests/test_admin.py +44 -0
- django_cache_cleaner-0.1.0/tests/test_commands_clear_cache.py +59 -0
- django_cache_cleaner-0.1.0/tests/test_metadata.py +34 -0
- django_cache_cleaner-0.1.0/tests/test_models.py +28 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024-present Fabio Caccamo
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: django-cache-cleaner
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: clear the entire cache or individual caches easily using the admin panel or management command.
|
|
5
|
+
Author-email: Fabio Caccamo <fabio.caccamo@gmail.com>
|
|
6
|
+
Maintainer-email: Fabio Caccamo <fabio.caccamo@gmail.com>
|
|
7
|
+
License: MIT License
|
|
8
|
+
|
|
9
|
+
Copyright (c) 2024-present Fabio Caccamo
|
|
10
|
+
|
|
11
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
12
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
13
|
+
in the Software without restriction, including without limitation the rights
|
|
14
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
15
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
16
|
+
furnished to do so, subject to the following conditions:
|
|
17
|
+
|
|
18
|
+
The above copyright notice and this permission notice shall be included in all
|
|
19
|
+
copies or substantial portions of the Software.
|
|
20
|
+
|
|
21
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
22
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
23
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
24
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
25
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
26
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
27
|
+
SOFTWARE.
|
|
28
|
+
|
|
29
|
+
Project-URL: Homepage, https://github.com/fabiocaccamo/django-cache-cleaner
|
|
30
|
+
Project-URL: Download, https://github.com/fabiocaccamo/django-cache-cleaner/releases
|
|
31
|
+
Project-URL: Documentation, https://github.com/fabiocaccamo/django-cache-cleaner#readme
|
|
32
|
+
Project-URL: Issues, https://github.com/fabiocaccamo/django-cache-cleaner/issues
|
|
33
|
+
Project-URL: Funding, https://github.com/sponsors/fabiocaccamo/
|
|
34
|
+
Project-URL: Twitter, https://twitter.com/fabiocaccamo
|
|
35
|
+
Keywords: django,cache,caches,cleaner,clear,clean,cleanup,command,management,purge
|
|
36
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
37
|
+
Classifier: Environment :: Web Environment
|
|
38
|
+
Classifier: Framework :: Django
|
|
39
|
+
Classifier: Framework :: Django :: 3.2
|
|
40
|
+
Classifier: Framework :: Django :: 4.0
|
|
41
|
+
Classifier: Framework :: Django :: 4.1
|
|
42
|
+
Classifier: Framework :: Django :: 4.2
|
|
43
|
+
Classifier: Framework :: Django :: 5.0
|
|
44
|
+
Classifier: Intended Audience :: Developers
|
|
45
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
46
|
+
Classifier: Natural Language :: English
|
|
47
|
+
Classifier: Operating System :: OS Independent
|
|
48
|
+
Classifier: Programming Language :: Python :: 3
|
|
49
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
50
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
51
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
52
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
53
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
54
|
+
Classifier: Topic :: Software Development :: Build Tools
|
|
55
|
+
Description-Content-Type: text/markdown
|
|
56
|
+
License-File: LICENSE.txt
|
|
57
|
+
|
|
58
|
+
[](https://www.python.org/)
|
|
59
|
+
[](https://www.djangoproject.com/)
|
|
60
|
+
|
|
61
|
+
[](https://pypi.org/project/django-cache-cleaner/)
|
|
62
|
+
[](https://pepy.tech/project/django-cache-cleaner)
|
|
63
|
+
[](https://github.com/fabiocaccamo/django-cache-cleaner/stargazers)
|
|
64
|
+
[](https://github.com/fabiocaccamo/django-cache-cleaner/blob/main/LICENSE.txt)
|
|
65
|
+
|
|
66
|
+
[](https://results.pre-commit.ci/latest/github/fabiocaccamo/django-cache-cleaner/main)
|
|
67
|
+
[](https://github.com/fabiocaccamo/django-cache-cleaner)
|
|
68
|
+
[](https://codecov.io/gh/fabiocaccamo/django-cache-cleaner)
|
|
69
|
+
<!-- [](https://www.codacy.com/app/fabiocaccamo/django-cache-cleaner) -->
|
|
70
|
+
[](https://codeclimate.com/github/fabiocaccamo/django-cache-cleaner/)
|
|
71
|
+
[](https://github.com/psf/black)
|
|
72
|
+
[](https://github.com/astral-sh/ruff)
|
|
73
|
+
|
|
74
|
+
# django-cache-cleaner
|
|
75
|
+
clear the entire cache or individual caches easily using the admin panel or management command.
|
|
76
|
+
|
|
77
|
+
## Installation
|
|
78
|
+
- Run `pip install django-cache-cleaner`
|
|
79
|
+
- Add `cache_cleaner` to `settings.INSTALLED_APPS`
|
|
80
|
+
- Run `python manage.py migrate`
|
|
81
|
+
- Restart your application server
|
|
82
|
+
|
|
83
|
+
## Usage
|
|
84
|
+
|
|
85
|
+
### Admin
|
|
86
|
+
To clear caches using the admin panel:
|
|
87
|
+
- ➡️ Navigate to the `Cache Cleaner / Caches`
|
|
88
|
+
- ✔️ Check the caches you want to clear
|
|
89
|
+
- 🧹 Select "Clear selected caches" from the actions menu
|
|
90
|
+
- ✨ Done :)
|
|
91
|
+
|
|
92
|
+
### Command
|
|
93
|
+
This package doesn't need any setting.
|
|
94
|
+
|
|
95
|
+
#### Clear default cache
|
|
96
|
+
```python
|
|
97
|
+
python manage.py clear_cache
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
#### Clear individual caches
|
|
101
|
+
```python
|
|
102
|
+
python manage.py clear_cache news products
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
#### Clear all caches
|
|
106
|
+
```python
|
|
107
|
+
python manage.py clear_cache --all
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## Testing
|
|
111
|
+
```bash
|
|
112
|
+
# clone repository
|
|
113
|
+
git clone https://github.com/fabiocaccamo/django-cache-cleaner.git && cd django-cache-cleaner
|
|
114
|
+
|
|
115
|
+
# create virtualenv and activate it
|
|
116
|
+
python -m venv venv && . venv/bin/activate
|
|
117
|
+
|
|
118
|
+
# upgrade pip
|
|
119
|
+
python -m pip install --upgrade pip
|
|
120
|
+
|
|
121
|
+
# install requirements
|
|
122
|
+
pip install -r requirements.txt -r requirements-test.txt
|
|
123
|
+
|
|
124
|
+
# install pre-commit to run formatters and linters
|
|
125
|
+
pre-commit install --install-hooks
|
|
126
|
+
|
|
127
|
+
# run tests
|
|
128
|
+
tox
|
|
129
|
+
# or
|
|
130
|
+
python runtests.py
|
|
131
|
+
# or
|
|
132
|
+
python -m django test --settings "tests.settings"
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
## License
|
|
137
|
+
Released under [MIT License](LICENSE.txt).
|
|
138
|
+
|
|
139
|
+
---
|
|
140
|
+
|
|
141
|
+
## Supporting
|
|
142
|
+
|
|
143
|
+
- :star: Star this project on [GitHub](https://github.com/fabiocaccamo/django-cache-cleaner)
|
|
144
|
+
- :octocat: Follow me on [GitHub](https://github.com/fabiocaccamo)
|
|
145
|
+
- :blue_heart: Follow me on [Twitter](https://twitter.com/fabiocaccamo)
|
|
146
|
+
- :moneybag: Sponsor me on [Github](https://github.com/sponsors/fabiocaccamo)
|
|
147
|
+
|
|
148
|
+
## See also
|
|
149
|
+
|
|
150
|
+
- [`django-admin-interface`](https://github.com/fabiocaccamo/django-admin-interface) - the default admin interface made customizable by the admin itself. popup windows replaced by modals. 🧙 ⚡
|
|
151
|
+
|
|
152
|
+
- [`django-colorfield`](https://github.com/fabiocaccamo/django-colorfield) - simple color field for models with a nice color-picker in the admin. 🎨
|
|
153
|
+
|
|
154
|
+
- [`django-extra-settings`](https://github.com/fabiocaccamo/django-extra-settings) - config and manage typed extra settings using just the django admin. ⚙️
|
|
155
|
+
|
|
156
|
+
- [`django-maintenance-mode`](https://github.com/fabiocaccamo/django-maintenance-mode) - shows a 503 error page when maintenance-mode is on. 🚧 🛠️
|
|
157
|
+
|
|
158
|
+
- [`django-redirects`](https://github.com/fabiocaccamo/django-redirects) - redirects with full control. ↪️
|
|
159
|
+
|
|
160
|
+
- [`django-treenode`](https://github.com/fabiocaccamo/django-treenode) - probably the best abstract model / admin for your tree based stuff. 🌳
|
|
161
|
+
|
|
162
|
+
- [`python-benedict`](https://github.com/fabiocaccamo/python-benedict) - dict subclass with keylist/keypath support, I/O shortcuts (base64, csv, json, pickle, plist, query-string, toml, xml, yaml) and many utilities. 📘
|
|
163
|
+
|
|
164
|
+
- [`python-codicefiscale`](https://github.com/fabiocaccamo/python-codicefiscale) - encode/decode Italian fiscal codes - codifica/decodifica del Codice Fiscale. 🇮🇹 💳
|
|
165
|
+
|
|
166
|
+
- [`python-fontbro`](https://github.com/fabiocaccamo/python-fontbro) - friendly font operations. 🧢
|
|
167
|
+
|
|
168
|
+
- [`python-fsutil`](https://github.com/fabiocaccamo/python-fsutil) - file-system utilities for lazy devs. 🧟♂️
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
[](https://www.python.org/)
|
|
2
|
+
[](https://www.djangoproject.com/)
|
|
3
|
+
|
|
4
|
+
[](https://pypi.org/project/django-cache-cleaner/)
|
|
5
|
+
[](https://pepy.tech/project/django-cache-cleaner)
|
|
6
|
+
[](https://github.com/fabiocaccamo/django-cache-cleaner/stargazers)
|
|
7
|
+
[](https://github.com/fabiocaccamo/django-cache-cleaner/blob/main/LICENSE.txt)
|
|
8
|
+
|
|
9
|
+
[](https://results.pre-commit.ci/latest/github/fabiocaccamo/django-cache-cleaner/main)
|
|
10
|
+
[](https://github.com/fabiocaccamo/django-cache-cleaner)
|
|
11
|
+
[](https://codecov.io/gh/fabiocaccamo/django-cache-cleaner)
|
|
12
|
+
<!-- [](https://www.codacy.com/app/fabiocaccamo/django-cache-cleaner) -->
|
|
13
|
+
[](https://codeclimate.com/github/fabiocaccamo/django-cache-cleaner/)
|
|
14
|
+
[](https://github.com/psf/black)
|
|
15
|
+
[](https://github.com/astral-sh/ruff)
|
|
16
|
+
|
|
17
|
+
# django-cache-cleaner
|
|
18
|
+
clear the entire cache or individual caches easily using the admin panel or management command.
|
|
19
|
+
|
|
20
|
+
## Installation
|
|
21
|
+
- Run `pip install django-cache-cleaner`
|
|
22
|
+
- Add `cache_cleaner` to `settings.INSTALLED_APPS`
|
|
23
|
+
- Run `python manage.py migrate`
|
|
24
|
+
- Restart your application server
|
|
25
|
+
|
|
26
|
+
## Usage
|
|
27
|
+
|
|
28
|
+
### Admin
|
|
29
|
+
To clear caches using the admin panel:
|
|
30
|
+
- ➡️ Navigate to the `Cache Cleaner / Caches`
|
|
31
|
+
- ✔️ Check the caches you want to clear
|
|
32
|
+
- 🧹 Select "Clear selected caches" from the actions menu
|
|
33
|
+
- ✨ Done :)
|
|
34
|
+
|
|
35
|
+
### Command
|
|
36
|
+
This package doesn't need any setting.
|
|
37
|
+
|
|
38
|
+
#### Clear default cache
|
|
39
|
+
```python
|
|
40
|
+
python manage.py clear_cache
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
#### Clear individual caches
|
|
44
|
+
```python
|
|
45
|
+
python manage.py clear_cache news products
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
#### Clear all caches
|
|
49
|
+
```python
|
|
50
|
+
python manage.py clear_cache --all
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Testing
|
|
54
|
+
```bash
|
|
55
|
+
# clone repository
|
|
56
|
+
git clone https://github.com/fabiocaccamo/django-cache-cleaner.git && cd django-cache-cleaner
|
|
57
|
+
|
|
58
|
+
# create virtualenv and activate it
|
|
59
|
+
python -m venv venv && . venv/bin/activate
|
|
60
|
+
|
|
61
|
+
# upgrade pip
|
|
62
|
+
python -m pip install --upgrade pip
|
|
63
|
+
|
|
64
|
+
# install requirements
|
|
65
|
+
pip install -r requirements.txt -r requirements-test.txt
|
|
66
|
+
|
|
67
|
+
# install pre-commit to run formatters and linters
|
|
68
|
+
pre-commit install --install-hooks
|
|
69
|
+
|
|
70
|
+
# run tests
|
|
71
|
+
tox
|
|
72
|
+
# or
|
|
73
|
+
python runtests.py
|
|
74
|
+
# or
|
|
75
|
+
python -m django test --settings "tests.settings"
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
## License
|
|
80
|
+
Released under [MIT License](LICENSE.txt).
|
|
81
|
+
|
|
82
|
+
---
|
|
83
|
+
|
|
84
|
+
## Supporting
|
|
85
|
+
|
|
86
|
+
- :star: Star this project on [GitHub](https://github.com/fabiocaccamo/django-cache-cleaner)
|
|
87
|
+
- :octocat: Follow me on [GitHub](https://github.com/fabiocaccamo)
|
|
88
|
+
- :blue_heart: Follow me on [Twitter](https://twitter.com/fabiocaccamo)
|
|
89
|
+
- :moneybag: Sponsor me on [Github](https://github.com/sponsors/fabiocaccamo)
|
|
90
|
+
|
|
91
|
+
## See also
|
|
92
|
+
|
|
93
|
+
- [`django-admin-interface`](https://github.com/fabiocaccamo/django-admin-interface) - the default admin interface made customizable by the admin itself. popup windows replaced by modals. 🧙 ⚡
|
|
94
|
+
|
|
95
|
+
- [`django-colorfield`](https://github.com/fabiocaccamo/django-colorfield) - simple color field for models with a nice color-picker in the admin. 🎨
|
|
96
|
+
|
|
97
|
+
- [`django-extra-settings`](https://github.com/fabiocaccamo/django-extra-settings) - config and manage typed extra settings using just the django admin. ⚙️
|
|
98
|
+
|
|
99
|
+
- [`django-maintenance-mode`](https://github.com/fabiocaccamo/django-maintenance-mode) - shows a 503 error page when maintenance-mode is on. 🚧 🛠️
|
|
100
|
+
|
|
101
|
+
- [`django-redirects`](https://github.com/fabiocaccamo/django-redirects) - redirects with full control. ↪️
|
|
102
|
+
|
|
103
|
+
- [`django-treenode`](https://github.com/fabiocaccamo/django-treenode) - probably the best abstract model / admin for your tree based stuff. 🌳
|
|
104
|
+
|
|
105
|
+
- [`python-benedict`](https://github.com/fabiocaccamo/python-benedict) - dict subclass with keylist/keypath support, I/O shortcuts (base64, csv, json, pickle, plist, query-string, toml, xml, yaml) and many utilities. 📘
|
|
106
|
+
|
|
107
|
+
- [`python-codicefiscale`](https://github.com/fabiocaccamo/python-codicefiscale) - encode/decode Italian fiscal codes - codifica/decodifica del Codice Fiscale. 🇮🇹 💳
|
|
108
|
+
|
|
109
|
+
- [`python-fontbro`](https://github.com/fabiocaccamo/python-fontbro) - friendly font operations. 🧢
|
|
110
|
+
|
|
111
|
+
- [`python-fsutil`](https://github.com/fabiocaccamo/python-fsutil) - file-system utilities for lazy devs. 🧟♂️
|
|
File without changes
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
from django.contrib import admin, messages
|
|
2
|
+
from django.core.cache import caches
|
|
3
|
+
from django.utils.translation import gettext_lazy as _
|
|
4
|
+
|
|
5
|
+
from cache_cleaner.models import Cache
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
@admin.action(description=_("Clear selected caches"))
|
|
9
|
+
def clear_caches(modeladmin, request, queryset):
|
|
10
|
+
for cache_obj in queryset:
|
|
11
|
+
cache_name = cache_obj.name
|
|
12
|
+
cache = caches[cache_name]
|
|
13
|
+
cache.clear()
|
|
14
|
+
caches_names = [cache_obj.name for cache_obj in queryset]
|
|
15
|
+
caches_names_str = ", ".join(caches_names)
|
|
16
|
+
messages.success(request, _("Cleared caches:") + f" {caches_names_str}.")
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
@admin.register(Cache)
|
|
20
|
+
class CacheAdmin(admin.ModelAdmin):
|
|
21
|
+
search_fields = ("name",)
|
|
22
|
+
list_display = ("name",)
|
|
23
|
+
actions = [clear_caches]
|
|
24
|
+
show_full_result_count = False
|
|
25
|
+
|
|
26
|
+
def get_queryset(self, request):
|
|
27
|
+
Cache.update_from_settings()
|
|
28
|
+
return super().get_queryset(request)
|
|
29
|
+
|
|
30
|
+
def has_add_permission(self, request, obj=None):
|
|
31
|
+
return False
|
|
32
|
+
|
|
33
|
+
def has_change_permission(self, request, obj=None):
|
|
34
|
+
return False
|
|
35
|
+
|
|
36
|
+
def has_delete_permission(self, request, obj=None):
|
|
37
|
+
return False
|
|
Binary file
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# SOME DESCRIPTIVE TITLE.
|
|
2
|
+
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
|
|
3
|
+
# This file is distributed under the same license as the PACKAGE package.
|
|
4
|
+
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
|
|
5
|
+
#
|
|
6
|
+
#, fuzzy
|
|
7
|
+
msgid ""
|
|
8
|
+
msgstr ""
|
|
9
|
+
"Project-Id-Version: PACKAGE VERSION\n"
|
|
10
|
+
"Report-Msgid-Bugs-To: \n"
|
|
11
|
+
"POT-Creation-Date: 2024-06-25 14:47-0500\n"
|
|
12
|
+
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
|
13
|
+
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
|
14
|
+
"Language-Team: LANGUAGE <LL@li.org>\n"
|
|
15
|
+
"Language: \n"
|
|
16
|
+
"MIME-Version: 1.0\n"
|
|
17
|
+
"Content-Type: text/plain; charset=UTF-8\n"
|
|
18
|
+
"Content-Transfer-Encoding: 8bit\n"
|
|
19
|
+
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
|
|
20
|
+
#: cache_cleaner/admin.py
|
|
21
|
+
msgid "Clear selected caches"
|
|
22
|
+
msgstr ""
|
|
23
|
+
|
|
24
|
+
#: cache_cleaner/admin.py
|
|
25
|
+
msgid "Cleared caches:"
|
|
26
|
+
msgstr "Cleared caches:"
|
|
27
|
+
|
|
28
|
+
#: cache_cleaner/apps.py
|
|
29
|
+
msgid "Cache Cleaner"
|
|
30
|
+
msgstr "Cache Cleaner"
|
|
31
|
+
|
|
32
|
+
#: cache_cleaner/models.py
|
|
33
|
+
msgid "Cache"
|
|
34
|
+
msgstr "Cache"
|
|
35
|
+
|
|
36
|
+
#: cache_cleaner/models.py
|
|
37
|
+
msgid "Caches"
|
|
38
|
+
msgstr "Caches"
|
|
39
|
+
|
|
40
|
+
#: cache_cleaner/models.py
|
|
41
|
+
msgid "Name"
|
|
42
|
+
msgstr "Name"
|
|
Binary file
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# SOME DESCRIPTIVE TITLE.
|
|
2
|
+
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
|
|
3
|
+
# This file is distributed under the same license as the PACKAGE package.
|
|
4
|
+
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
|
|
5
|
+
#
|
|
6
|
+
#, fuzzy
|
|
7
|
+
msgid ""
|
|
8
|
+
msgstr ""
|
|
9
|
+
"Project-Id-Version: PACKAGE VERSION\n"
|
|
10
|
+
"Report-Msgid-Bugs-To: \n"
|
|
11
|
+
"POT-Creation-Date: 2024-06-25 14:47-0500\n"
|
|
12
|
+
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
|
13
|
+
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
|
14
|
+
"Language-Team: LANGUAGE <LL@li.org>\n"
|
|
15
|
+
"Language: \n"
|
|
16
|
+
"MIME-Version: 1.0\n"
|
|
17
|
+
"Content-Type: text/plain; charset=UTF-8\n"
|
|
18
|
+
"Content-Transfer-Encoding: 8bit\n"
|
|
19
|
+
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
|
|
20
|
+
#: cache_cleaner/admin.py
|
|
21
|
+
msgid "Clear selected caches"
|
|
22
|
+
msgstr ""
|
|
23
|
+
|
|
24
|
+
#: cache_cleaner/admin.py
|
|
25
|
+
msgid "Cleared caches:"
|
|
26
|
+
msgstr "Cleared caches:"
|
|
27
|
+
|
|
28
|
+
#: cache_cleaner/apps.py
|
|
29
|
+
msgid "Cache Cleaner"
|
|
30
|
+
msgstr "Cache Cleaner"
|
|
31
|
+
|
|
32
|
+
#: cache_cleaner/models.py
|
|
33
|
+
msgid "Cache"
|
|
34
|
+
msgstr "Cache"
|
|
35
|
+
|
|
36
|
+
#: cache_cleaner/models.py
|
|
37
|
+
msgid "Caches"
|
|
38
|
+
msgstr "Caches"
|
|
39
|
+
|
|
40
|
+
#: cache_cleaner/models.py
|
|
41
|
+
msgid "Name"
|
|
42
|
+
msgstr "Nome"
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
from django.core.cache import cache, caches
|
|
2
|
+
from django.core.management.base import BaseCommand
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class Command(BaseCommand):
|
|
6
|
+
"""
|
|
7
|
+
A Django management command to clear the cache.
|
|
8
|
+
This command allows you to clear the entire cache or individual caches.
|
|
9
|
+
|
|
10
|
+
Options:
|
|
11
|
+
cache_names (list, optional): A list of one or more cache names to clear.
|
|
12
|
+
--all (bool, optional): A flag to clear all defined cache backends.
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
help = "Clear the entire cache or individual caches."
|
|
16
|
+
|
|
17
|
+
def _stdout_success(self, message):
|
|
18
|
+
self.stdout.write(self.style.SUCCESS(message))
|
|
19
|
+
|
|
20
|
+
def _stdout_error(self, message):
|
|
21
|
+
self.stderr.write(self.style.ERROR(message))
|
|
22
|
+
|
|
23
|
+
def add_arguments(self, parser):
|
|
24
|
+
"""
|
|
25
|
+
Adds arguments to the command parser.
|
|
26
|
+
|
|
27
|
+
* cache_names: A list of cache names to clear.
|
|
28
|
+
* --all: A flag to clear all caches.
|
|
29
|
+
"""
|
|
30
|
+
parser.add_argument(
|
|
31
|
+
"cache_names",
|
|
32
|
+
nargs="*",
|
|
33
|
+
type=str,
|
|
34
|
+
help="List of specific cache names to clear",
|
|
35
|
+
)
|
|
36
|
+
parser.add_argument(
|
|
37
|
+
"--all",
|
|
38
|
+
action="store_true",
|
|
39
|
+
dest="clear_all",
|
|
40
|
+
help="Clear all caches",
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
def _clear_all_caches(self):
|
|
44
|
+
for cache_name in caches:
|
|
45
|
+
caches[cache_name].clear()
|
|
46
|
+
self._stdout_success(f"Cleared cache '{cache_name}'!")
|
|
47
|
+
self._stdout_success("Cleared all caches!")
|
|
48
|
+
|
|
49
|
+
def _clear_default_cache(self):
|
|
50
|
+
cache.clear()
|
|
51
|
+
self._stdout_success("Cleared default cache!")
|
|
52
|
+
|
|
53
|
+
def _clear_individual_caches(self, cache_names):
|
|
54
|
+
for cache_name in cache_names:
|
|
55
|
+
if cache_name in caches:
|
|
56
|
+
caches[cache_name].clear()
|
|
57
|
+
self._stdout_success(f"Cleared cache '{cache_name}'!")
|
|
58
|
+
else:
|
|
59
|
+
self._stdout_error(f"Cache '{cache_name}' does not exist!")
|
|
60
|
+
|
|
61
|
+
def handle(self, *args, **options):
|
|
62
|
+
"""
|
|
63
|
+
Handles the cache clearing based on the provided arguments.
|
|
64
|
+
|
|
65
|
+
* If `clear_all` is True, clears all defined cache backends.
|
|
66
|
+
* If specific `cache_names` are provided, clears those caches if they exist.
|
|
67
|
+
* If no arguments are provided, clears the default cache.
|
|
68
|
+
"""
|
|
69
|
+
cache_names = options["cache_names"]
|
|
70
|
+
clear_all = options["clear_all"]
|
|
71
|
+
if clear_all:
|
|
72
|
+
self._clear_all_caches()
|
|
73
|
+
elif cache_names:
|
|
74
|
+
self._clear_individual_caches(cache_names)
|
|
75
|
+
else:
|
|
76
|
+
self._clear_default_cache()
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
__author__ = "Fabio Caccamo"
|
|
2
|
+
__copyright__ = "Copyright (c) 2024-present Fabio Caccamo"
|
|
3
|
+
__description__ = (
|
|
4
|
+
"clear the entire cache or individual caches easily "
|
|
5
|
+
"using the admin panel or management command."
|
|
6
|
+
)
|
|
7
|
+
__email__ = "fabio.caccamo@gmail.com"
|
|
8
|
+
__license__ = "MIT"
|
|
9
|
+
__title__ = "django-cache-cleaner"
|
|
10
|
+
__version__ = "0.1.0"
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
from django.db import migrations, models
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class Migration(migrations.Migration):
|
|
5
|
+
initial = True
|
|
6
|
+
|
|
7
|
+
dependencies = []
|
|
8
|
+
|
|
9
|
+
operations = [
|
|
10
|
+
migrations.CreateModel(
|
|
11
|
+
name="Cache",
|
|
12
|
+
fields=[
|
|
13
|
+
(
|
|
14
|
+
"name",
|
|
15
|
+
models.CharField(
|
|
16
|
+
max_length=255,
|
|
17
|
+
primary_key=True,
|
|
18
|
+
serialize=False,
|
|
19
|
+
verbose_name="Name",
|
|
20
|
+
),
|
|
21
|
+
),
|
|
22
|
+
],
|
|
23
|
+
options={
|
|
24
|
+
"verbose_name": "Cache",
|
|
25
|
+
"verbose_name_plural": "Caches",
|
|
26
|
+
"ordering": ["name"],
|
|
27
|
+
},
|
|
28
|
+
),
|
|
29
|
+
]
|
|
File without changes
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
from django.conf import settings
|
|
2
|
+
from django.db import models, transaction
|
|
3
|
+
from django.utils.translation import gettext_lazy as _
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class Cache(models.Model):
|
|
7
|
+
class Meta:
|
|
8
|
+
ordering = ["name"]
|
|
9
|
+
verbose_name = _("Cache")
|
|
10
|
+
verbose_name_plural = _("Caches")
|
|
11
|
+
|
|
12
|
+
@classmethod
|
|
13
|
+
def update_from_settings(cls):
|
|
14
|
+
manager = cls.objects
|
|
15
|
+
settings_caches = set(settings.CACHES.keys())
|
|
16
|
+
existing_caches = set(manager.values_list("name", flat=True))
|
|
17
|
+
caches_to_create = settings_caches - existing_caches
|
|
18
|
+
caches_to_delete = existing_caches - settings_caches
|
|
19
|
+
|
|
20
|
+
with transaction.atomic():
|
|
21
|
+
if caches_to_create:
|
|
22
|
+
manager.bulk_create(
|
|
23
|
+
[Cache(name=cache_name) for cache_name in caches_to_create]
|
|
24
|
+
)
|
|
25
|
+
if caches_to_delete:
|
|
26
|
+
manager.filter(name__in=caches_to_delete).delete()
|
|
27
|
+
|
|
28
|
+
name = models.CharField(
|
|
29
|
+
verbose_name=_("Name"),
|
|
30
|
+
primary_key=True,
|
|
31
|
+
max_length=255,
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
def __str__(self):
|
|
35
|
+
return f"{self.name}"
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: django-cache-cleaner
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: clear the entire cache or individual caches easily using the admin panel or management command.
|
|
5
|
+
Author-email: Fabio Caccamo <fabio.caccamo@gmail.com>
|
|
6
|
+
Maintainer-email: Fabio Caccamo <fabio.caccamo@gmail.com>
|
|
7
|
+
License: MIT License
|
|
8
|
+
|
|
9
|
+
Copyright (c) 2024-present Fabio Caccamo
|
|
10
|
+
|
|
11
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
12
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
13
|
+
in the Software without restriction, including without limitation the rights
|
|
14
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
15
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
16
|
+
furnished to do so, subject to the following conditions:
|
|
17
|
+
|
|
18
|
+
The above copyright notice and this permission notice shall be included in all
|
|
19
|
+
copies or substantial portions of the Software.
|
|
20
|
+
|
|
21
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
22
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
23
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
24
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
25
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
26
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
27
|
+
SOFTWARE.
|
|
28
|
+
|
|
29
|
+
Project-URL: Homepage, https://github.com/fabiocaccamo/django-cache-cleaner
|
|
30
|
+
Project-URL: Download, https://github.com/fabiocaccamo/django-cache-cleaner/releases
|
|
31
|
+
Project-URL: Documentation, https://github.com/fabiocaccamo/django-cache-cleaner#readme
|
|
32
|
+
Project-URL: Issues, https://github.com/fabiocaccamo/django-cache-cleaner/issues
|
|
33
|
+
Project-URL: Funding, https://github.com/sponsors/fabiocaccamo/
|
|
34
|
+
Project-URL: Twitter, https://twitter.com/fabiocaccamo
|
|
35
|
+
Keywords: django,cache,caches,cleaner,clear,clean,cleanup,command,management,purge
|
|
36
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
37
|
+
Classifier: Environment :: Web Environment
|
|
38
|
+
Classifier: Framework :: Django
|
|
39
|
+
Classifier: Framework :: Django :: 3.2
|
|
40
|
+
Classifier: Framework :: Django :: 4.0
|
|
41
|
+
Classifier: Framework :: Django :: 4.1
|
|
42
|
+
Classifier: Framework :: Django :: 4.2
|
|
43
|
+
Classifier: Framework :: Django :: 5.0
|
|
44
|
+
Classifier: Intended Audience :: Developers
|
|
45
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
46
|
+
Classifier: Natural Language :: English
|
|
47
|
+
Classifier: Operating System :: OS Independent
|
|
48
|
+
Classifier: Programming Language :: Python :: 3
|
|
49
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
50
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
51
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
52
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
53
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
54
|
+
Classifier: Topic :: Software Development :: Build Tools
|
|
55
|
+
Description-Content-Type: text/markdown
|
|
56
|
+
License-File: LICENSE.txt
|
|
57
|
+
|
|
58
|
+
[](https://www.python.org/)
|
|
59
|
+
[](https://www.djangoproject.com/)
|
|
60
|
+
|
|
61
|
+
[](https://pypi.org/project/django-cache-cleaner/)
|
|
62
|
+
[](https://pepy.tech/project/django-cache-cleaner)
|
|
63
|
+
[](https://github.com/fabiocaccamo/django-cache-cleaner/stargazers)
|
|
64
|
+
[](https://github.com/fabiocaccamo/django-cache-cleaner/blob/main/LICENSE.txt)
|
|
65
|
+
|
|
66
|
+
[](https://results.pre-commit.ci/latest/github/fabiocaccamo/django-cache-cleaner/main)
|
|
67
|
+
[](https://github.com/fabiocaccamo/django-cache-cleaner)
|
|
68
|
+
[](https://codecov.io/gh/fabiocaccamo/django-cache-cleaner)
|
|
69
|
+
<!-- [](https://www.codacy.com/app/fabiocaccamo/django-cache-cleaner) -->
|
|
70
|
+
[](https://codeclimate.com/github/fabiocaccamo/django-cache-cleaner/)
|
|
71
|
+
[](https://github.com/psf/black)
|
|
72
|
+
[](https://github.com/astral-sh/ruff)
|
|
73
|
+
|
|
74
|
+
# django-cache-cleaner
|
|
75
|
+
clear the entire cache or individual caches easily using the admin panel or management command.
|
|
76
|
+
|
|
77
|
+
## Installation
|
|
78
|
+
- Run `pip install django-cache-cleaner`
|
|
79
|
+
- Add `cache_cleaner` to `settings.INSTALLED_APPS`
|
|
80
|
+
- Run `python manage.py migrate`
|
|
81
|
+
- Restart your application server
|
|
82
|
+
|
|
83
|
+
## Usage
|
|
84
|
+
|
|
85
|
+
### Admin
|
|
86
|
+
To clear caches using the admin panel:
|
|
87
|
+
- ➡️ Navigate to the `Cache Cleaner / Caches`
|
|
88
|
+
- ✔️ Check the caches you want to clear
|
|
89
|
+
- 🧹 Select "Clear selected caches" from the actions menu
|
|
90
|
+
- ✨ Done :)
|
|
91
|
+
|
|
92
|
+
### Command
|
|
93
|
+
This package doesn't need any setting.
|
|
94
|
+
|
|
95
|
+
#### Clear default cache
|
|
96
|
+
```python
|
|
97
|
+
python manage.py clear_cache
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
#### Clear individual caches
|
|
101
|
+
```python
|
|
102
|
+
python manage.py clear_cache news products
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
#### Clear all caches
|
|
106
|
+
```python
|
|
107
|
+
python manage.py clear_cache --all
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## Testing
|
|
111
|
+
```bash
|
|
112
|
+
# clone repository
|
|
113
|
+
git clone https://github.com/fabiocaccamo/django-cache-cleaner.git && cd django-cache-cleaner
|
|
114
|
+
|
|
115
|
+
# create virtualenv and activate it
|
|
116
|
+
python -m venv venv && . venv/bin/activate
|
|
117
|
+
|
|
118
|
+
# upgrade pip
|
|
119
|
+
python -m pip install --upgrade pip
|
|
120
|
+
|
|
121
|
+
# install requirements
|
|
122
|
+
pip install -r requirements.txt -r requirements-test.txt
|
|
123
|
+
|
|
124
|
+
# install pre-commit to run formatters and linters
|
|
125
|
+
pre-commit install --install-hooks
|
|
126
|
+
|
|
127
|
+
# run tests
|
|
128
|
+
tox
|
|
129
|
+
# or
|
|
130
|
+
python runtests.py
|
|
131
|
+
# or
|
|
132
|
+
python -m django test --settings "tests.settings"
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
## License
|
|
137
|
+
Released under [MIT License](LICENSE.txt).
|
|
138
|
+
|
|
139
|
+
---
|
|
140
|
+
|
|
141
|
+
## Supporting
|
|
142
|
+
|
|
143
|
+
- :star: Star this project on [GitHub](https://github.com/fabiocaccamo/django-cache-cleaner)
|
|
144
|
+
- :octocat: Follow me on [GitHub](https://github.com/fabiocaccamo)
|
|
145
|
+
- :blue_heart: Follow me on [Twitter](https://twitter.com/fabiocaccamo)
|
|
146
|
+
- :moneybag: Sponsor me on [Github](https://github.com/sponsors/fabiocaccamo)
|
|
147
|
+
|
|
148
|
+
## See also
|
|
149
|
+
|
|
150
|
+
- [`django-admin-interface`](https://github.com/fabiocaccamo/django-admin-interface) - the default admin interface made customizable by the admin itself. popup windows replaced by modals. 🧙 ⚡
|
|
151
|
+
|
|
152
|
+
- [`django-colorfield`](https://github.com/fabiocaccamo/django-colorfield) - simple color field for models with a nice color-picker in the admin. 🎨
|
|
153
|
+
|
|
154
|
+
- [`django-extra-settings`](https://github.com/fabiocaccamo/django-extra-settings) - config and manage typed extra settings using just the django admin. ⚙️
|
|
155
|
+
|
|
156
|
+
- [`django-maintenance-mode`](https://github.com/fabiocaccamo/django-maintenance-mode) - shows a 503 error page when maintenance-mode is on. 🚧 🛠️
|
|
157
|
+
|
|
158
|
+
- [`django-redirects`](https://github.com/fabiocaccamo/django-redirects) - redirects with full control. ↪️
|
|
159
|
+
|
|
160
|
+
- [`django-treenode`](https://github.com/fabiocaccamo/django-treenode) - probably the best abstract model / admin for your tree based stuff. 🌳
|
|
161
|
+
|
|
162
|
+
- [`python-benedict`](https://github.com/fabiocaccamo/python-benedict) - dict subclass with keylist/keypath support, I/O shortcuts (base64, csv, json, pickle, plist, query-string, toml, xml, yaml) and many utilities. 📘
|
|
163
|
+
|
|
164
|
+
- [`python-codicefiscale`](https://github.com/fabiocaccamo/python-codicefiscale) - encode/decode Italian fiscal codes - codifica/decodifica del Codice Fiscale. 🇮🇹 💳
|
|
165
|
+
|
|
166
|
+
- [`python-fontbro`](https://github.com/fabiocaccamo/python-fontbro) - friendly font operations. 🧢
|
|
167
|
+
|
|
168
|
+
- [`python-fsutil`](https://github.com/fabiocaccamo/python-fsutil) - file-system utilities for lazy devs. 🧟♂️
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
LICENSE.txt
|
|
2
|
+
MANIFEST.in
|
|
3
|
+
README.md
|
|
4
|
+
pyproject.toml
|
|
5
|
+
setup.py
|
|
6
|
+
cache_cleaner/__init__.py
|
|
7
|
+
cache_cleaner/admin.py
|
|
8
|
+
cache_cleaner/apps.py
|
|
9
|
+
cache_cleaner/metadata.py
|
|
10
|
+
cache_cleaner/models.py
|
|
11
|
+
cache_cleaner/locale/en/LC_MESSAGES/django.mo
|
|
12
|
+
cache_cleaner/locale/en/LC_MESSAGES/django.po
|
|
13
|
+
cache_cleaner/locale/it/LC_MESSAGES/django.mo
|
|
14
|
+
cache_cleaner/locale/it/LC_MESSAGES/django.po
|
|
15
|
+
cache_cleaner/management/__init__.py
|
|
16
|
+
cache_cleaner/management/commands/__init__.py
|
|
17
|
+
cache_cleaner/management/commands/clear_cache.py
|
|
18
|
+
cache_cleaner/migrations/0001_initial.py
|
|
19
|
+
cache_cleaner/migrations/__init__.py
|
|
20
|
+
django_cache_cleaner.egg-info/PKG-INFO
|
|
21
|
+
django_cache_cleaner.egg-info/SOURCES.txt
|
|
22
|
+
django_cache_cleaner.egg-info/dependency_links.txt
|
|
23
|
+
django_cache_cleaner.egg-info/top_level.txt
|
|
24
|
+
tests/test_admin.py
|
|
25
|
+
tests/test_commands_clear_cache.py
|
|
26
|
+
tests/test_metadata.py
|
|
27
|
+
tests/test_models.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
cache_cleaner
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "django-cache-cleaner"
|
|
7
|
+
description = "clear the entire cache or individual caches easily using the admin panel or management command."
|
|
8
|
+
authors = [
|
|
9
|
+
{ name = "Fabio Caccamo", email = "fabio.caccamo@gmail.com" },
|
|
10
|
+
]
|
|
11
|
+
keywords = [
|
|
12
|
+
"django",
|
|
13
|
+
"cache",
|
|
14
|
+
"caches",
|
|
15
|
+
"cleaner",
|
|
16
|
+
"clear",
|
|
17
|
+
"clean",
|
|
18
|
+
"cleanup",
|
|
19
|
+
"command",
|
|
20
|
+
"management",
|
|
21
|
+
"purge",
|
|
22
|
+
]
|
|
23
|
+
classifiers = [
|
|
24
|
+
"Development Status :: 5 - Production/Stable",
|
|
25
|
+
"Environment :: Web Environment",
|
|
26
|
+
"Framework :: Django",
|
|
27
|
+
"Framework :: Django :: 3.2",
|
|
28
|
+
"Framework :: Django :: 4.0",
|
|
29
|
+
"Framework :: Django :: 4.1",
|
|
30
|
+
"Framework :: Django :: 4.2",
|
|
31
|
+
"Framework :: Django :: 5.0",
|
|
32
|
+
"Intended Audience :: Developers",
|
|
33
|
+
"License :: OSI Approved :: MIT License",
|
|
34
|
+
"Natural Language :: English",
|
|
35
|
+
"Operating System :: OS Independent",
|
|
36
|
+
"Programming Language :: Python :: 3",
|
|
37
|
+
"Programming Language :: Python :: 3.8",
|
|
38
|
+
"Programming Language :: Python :: 3.9",
|
|
39
|
+
"Programming Language :: Python :: 3.10",
|
|
40
|
+
"Programming Language :: Python :: 3.11",
|
|
41
|
+
"Programming Language :: Python :: 3.12",
|
|
42
|
+
"Topic :: Software Development :: Build Tools",
|
|
43
|
+
]
|
|
44
|
+
dependencies = [
|
|
45
|
+
]
|
|
46
|
+
dynamic = ["version"]
|
|
47
|
+
maintainers = [
|
|
48
|
+
{ name = "Fabio Caccamo", email = "fabio.caccamo@gmail.com" },
|
|
49
|
+
]
|
|
50
|
+
|
|
51
|
+
[project.readme]
|
|
52
|
+
file = "README.md"
|
|
53
|
+
content-type = "text/markdown"
|
|
54
|
+
|
|
55
|
+
[project.license]
|
|
56
|
+
file = "LICENSE.txt"
|
|
57
|
+
content-type = "text/plain"
|
|
58
|
+
|
|
59
|
+
[project.urls]
|
|
60
|
+
Homepage = "https://github.com/fabiocaccamo/django-cache-cleaner"
|
|
61
|
+
Download = "https://github.com/fabiocaccamo/django-cache-cleaner/releases"
|
|
62
|
+
Documentation = "https://github.com/fabiocaccamo/django-cache-cleaner#readme"
|
|
63
|
+
Issues = "https://github.com/fabiocaccamo/django-cache-cleaner/issues"
|
|
64
|
+
Funding = "https://github.com/sponsors/fabiocaccamo/"
|
|
65
|
+
Twitter = "https://twitter.com/fabiocaccamo"
|
|
66
|
+
|
|
67
|
+
[tool.black]
|
|
68
|
+
line-length = 88
|
|
69
|
+
include = '\.pyi?$'
|
|
70
|
+
exclude = '''
|
|
71
|
+
/(
|
|
72
|
+
\.git
|
|
73
|
+
| \.hg
|
|
74
|
+
| \.mypy_cache
|
|
75
|
+
| \.tox
|
|
76
|
+
| \.venv
|
|
77
|
+
| _build
|
|
78
|
+
| buck-out
|
|
79
|
+
| build
|
|
80
|
+
| dist
|
|
81
|
+
| venv
|
|
82
|
+
)/
|
|
83
|
+
'''
|
|
84
|
+
|
|
85
|
+
[tool.ruff]
|
|
86
|
+
line-length = 88
|
|
87
|
+
|
|
88
|
+
[tool.ruff.lint]
|
|
89
|
+
ignore = []
|
|
90
|
+
select = ["B", "B9", "C", "E", "F", "W"]
|
|
91
|
+
|
|
92
|
+
[tool.ruff.lint.mccabe]
|
|
93
|
+
max-complexity = 10
|
|
94
|
+
|
|
95
|
+
[tool.setuptools.packages.find]
|
|
96
|
+
include = ["cache_cleaner*"]
|
|
97
|
+
|
|
98
|
+
[tool.setuptools.dynamic.version]
|
|
99
|
+
attr = "cache_cleaner.metadata.__version__"
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
from django.contrib.admin.sites import AdminSite
|
|
2
|
+
from django.test import TestCase, RequestFactory
|
|
3
|
+
from django.test import Client
|
|
4
|
+
from django.contrib.auth.models import User
|
|
5
|
+
from unittest.mock import patch
|
|
6
|
+
from cache_cleaner.models import Cache
|
|
7
|
+
from cache_cleaner.admin import CacheAdmin
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class CacheAdminTest(TestCase):
|
|
11
|
+
def setUp(self):
|
|
12
|
+
self._superuser = User.objects.create_superuser(
|
|
13
|
+
"admin",
|
|
14
|
+
"admin@example.com",
|
|
15
|
+
"password",
|
|
16
|
+
)
|
|
17
|
+
self._client = Client()
|
|
18
|
+
self._client.force_login(self._superuser)
|
|
19
|
+
self._request = RequestFactory()
|
|
20
|
+
self._url = "/admin/cache_cleaner/cache/"
|
|
21
|
+
self._admin_site = AdminSite()
|
|
22
|
+
self._cache_admin = CacheAdmin(Cache, self._admin_site)
|
|
23
|
+
|
|
24
|
+
def test_get_queryset_calls_update_from_settings(self):
|
|
25
|
+
with patch.object(Cache, "update_from_settings") as mock_update_from_settings:
|
|
26
|
+
request = self._request.get(self._url)
|
|
27
|
+
request.user = self._superuser
|
|
28
|
+
self._cache_admin.get_queryset(request)
|
|
29
|
+
mock_update_from_settings.assert_called_once()
|
|
30
|
+
|
|
31
|
+
def test_has_add_permission(self):
|
|
32
|
+
request = self._request.get(self._url)
|
|
33
|
+
request.user = self._superuser
|
|
34
|
+
self.assertFalse(self._cache_admin.has_add_permission(request))
|
|
35
|
+
|
|
36
|
+
def test_has_change_permission(self):
|
|
37
|
+
request = self._request.get(self._url)
|
|
38
|
+
request.user = self._superuser
|
|
39
|
+
self.assertFalse(self._cache_admin.has_change_permission(request))
|
|
40
|
+
|
|
41
|
+
def test_has_delete_permission(self):
|
|
42
|
+
request = self._request.get(self._url)
|
|
43
|
+
request.user = self._superuser
|
|
44
|
+
self.assertFalse(self._cache_admin.has_delete_permission(request))
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import re
|
|
2
|
+
from io import StringIO
|
|
3
|
+
|
|
4
|
+
from django.core.management import call_command
|
|
5
|
+
from django.test import TestCase
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class ClearCacheCommandTests(TestCase):
|
|
9
|
+
def _remove_ansi_escape_codes(self, text):
|
|
10
|
+
ansi_escape = re.compile(r"\x1b\[[0-9;]*m")
|
|
11
|
+
return ansi_escape.sub("", text)
|
|
12
|
+
|
|
13
|
+
def _output_to_str(self, output):
|
|
14
|
+
output_str = output.getvalue()
|
|
15
|
+
output_str = self._remove_ansi_escape_codes(output_str)
|
|
16
|
+
output_str = output_str.strip()
|
|
17
|
+
return output_str
|
|
18
|
+
|
|
19
|
+
def _call_command(self, *args, **kwargs):
|
|
20
|
+
output = StringIO()
|
|
21
|
+
error = StringIO()
|
|
22
|
+
call_command(
|
|
23
|
+
"clear_cache",
|
|
24
|
+
*args,
|
|
25
|
+
stdout=output,
|
|
26
|
+
stderr=error,
|
|
27
|
+
**kwargs,
|
|
28
|
+
)
|
|
29
|
+
output_str = self._output_to_str(output)
|
|
30
|
+
error_str = self._output_to_str(error)
|
|
31
|
+
return (output_str, error_str)
|
|
32
|
+
|
|
33
|
+
def test_without_args(self):
|
|
34
|
+
out, _ = self._call_command()
|
|
35
|
+
self.assertEqual(out, "Cleared default cache!")
|
|
36
|
+
|
|
37
|
+
def test_with_all_arg(self):
|
|
38
|
+
out, _ = self._call_command(all=True)
|
|
39
|
+
self.assertEqual(
|
|
40
|
+
out,
|
|
41
|
+
"Cleared cache 'default'!\n"
|
|
42
|
+
"Cleared cache 'cache_1'!\n"
|
|
43
|
+
"Cleared cache 'cache_2'!\n"
|
|
44
|
+
"Cleared cache 'cache_3'!\n"
|
|
45
|
+
"Cleared all caches!",
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
def test_with_valid_cache_names_args(self):
|
|
49
|
+
out, _ = self._call_command("default", "cache_1", "cache_3")
|
|
50
|
+
self.assertEqual(
|
|
51
|
+
out,
|
|
52
|
+
"Cleared cache 'default'!\n"
|
|
53
|
+
"Cleared cache 'cache_1'!\n"
|
|
54
|
+
"Cleared cache 'cache_3'!",
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
def test_with_invalid_cache_names_args(self):
|
|
58
|
+
_, err = self._call_command("unknown")
|
|
59
|
+
self.assertEqual(err, "Cache 'unknown' does not exist!")
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import re
|
|
2
|
+
|
|
3
|
+
from django.test import TestCase
|
|
4
|
+
|
|
5
|
+
from cache_cleaner.metadata import (
|
|
6
|
+
__author__,
|
|
7
|
+
__copyright__,
|
|
8
|
+
__description__,
|
|
9
|
+
__email__,
|
|
10
|
+
__license__,
|
|
11
|
+
__title__,
|
|
12
|
+
__version__,
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class MetadataTestCase(TestCase):
|
|
17
|
+
"""
|
|
18
|
+
This class describes a metadata test case.
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
def test_metadata(self):
|
|
22
|
+
self.assertTrue(isinstance(__author__, str))
|
|
23
|
+
self.assertTrue(isinstance(__copyright__, str))
|
|
24
|
+
self.assertTrue(isinstance(__description__, str))
|
|
25
|
+
self.assertTrue(isinstance(__email__, str))
|
|
26
|
+
self.assertTrue(isinstance(__license__, str))
|
|
27
|
+
self.assertTrue(isinstance(__title__, str))
|
|
28
|
+
self.assertTrue(isinstance(__version__, str))
|
|
29
|
+
|
|
30
|
+
def test_version(self):
|
|
31
|
+
v = __version__
|
|
32
|
+
v_re = re.compile(r"^([0-9]+)(\.([0-9]+)){1,2}$")
|
|
33
|
+
v_match = v_re.match(v)
|
|
34
|
+
self.assertTrue(v_match is not None)
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
from django.test import TestCase, override_settings
|
|
2
|
+
from cache_cleaner.models import Cache
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class CacheModelTest(TestCase):
|
|
6
|
+
def setUp(self):
|
|
7
|
+
self._cache_1 = Cache.objects.create(name="dummy_cache_1")
|
|
8
|
+
self._cache_2 = Cache.objects.create(name="dummy_cache_2")
|
|
9
|
+
|
|
10
|
+
def test_name_field(self):
|
|
11
|
+
self.assertEqual(self._cache_1.name, "dummy_cache_1")
|
|
12
|
+
self.assertEqual(self._cache_2.name, "dummy_cache_2")
|
|
13
|
+
self.assertTrue(isinstance(self._cache_1, Cache))
|
|
14
|
+
self.assertTrue(isinstance(self._cache_2, Cache))
|
|
15
|
+
|
|
16
|
+
def test_str_method(self):
|
|
17
|
+
self.assertEqual(str(self._cache_1), "dummy_cache_1")
|
|
18
|
+
self.assertEqual(str(self._cache_2), "dummy_cache_2")
|
|
19
|
+
|
|
20
|
+
@override_settings(CACHES={"project_cache_1": {}, "project_cache_2": {}})
|
|
21
|
+
def test_update_from_settings(self):
|
|
22
|
+
self.assertTrue(Cache.objects.filter(name="dummy_cache_1").exists())
|
|
23
|
+
self.assertTrue(Cache.objects.filter(name="dummy_cache_2").exists())
|
|
24
|
+
Cache.update_from_settings()
|
|
25
|
+
self.assertFalse(Cache.objects.filter(name="dummy_cache_1").exists())
|
|
26
|
+
self.assertFalse(Cache.objects.filter(name="dummy_cache_2").exists())
|
|
27
|
+
self.assertTrue(Cache.objects.filter(name="project_cache_1").exists())
|
|
28
|
+
self.assertTrue(Cache.objects.filter(name="project_cache_2").exists())
|