Skip to content

Commit f2c9c36

Browse files
authored
Merge pull request #18 from ycharts/version_1
Major Upgrades
2 parents ee57529 + a735271 commit f2c9c36

File tree

17 files changed

+430
-177
lines changed

17 files changed

+430
-177
lines changed

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,3 @@ A few sentences or bullet points describing the overall goals and what changed.
44
### How to test
55
- [ ] Step 1 to test the changes you made
66
- [ ] Step 2 to test the changes you made
7-

.github/workflows/canceller.yml

Lines changed: 0 additions & 18 deletions
This file was deleted.

.github/workflows/main.yml

Lines changed: 37 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,38 @@
1-
name: Test Suite # IMPORTANT: If this name changes you need to update the canceller.yml
1+
name: Test Suite
22

33
# Controls when the action will run.
44
on:
55
# Triggers the workflow on push for the master branch.
66
push:
77
branches: [ master ]
8-
98
# Triggers the workflow on pull request for any branch.
109
pull_request:
11-
1210
# Allows you to run this workflow manually from the Actions tab.
1311
workflow_dispatch:
1412

13+
concurrency:
14+
group: ${{ github.workflow }}-${{ github.ref }}
15+
cancel-in-progress: true
16+
1517
jobs:
1618
build:
17-
runs-on: ubuntu-18.04
19+
runs-on: ubuntu-latest
1820
strategy:
1921
matrix:
20-
python-version: [ 3.4, 3.5, 3.6, 3.7 ]
21-
django-version: [ 1.7.*, 1.8.*, 1.9.*, 1.10.*, 1.11.*, 2.0.*, 2.1.*, 2.2.*, 3.0.* ]
22-
exclude:
23-
- python-version: 3.4
24-
django-version: 2.1.*
25-
- python-version: 3.4
26-
django-version: 2.2.*
27-
- python-version: 3.4
28-
django-version: 3.0.*
29-
- python-version: 3.5
30-
django-version: 1.7.*
31-
- python-version: 3.5
32-
django-version: 3.0.*
33-
- python-version: 3.6
34-
django-version: 1.7.*
35-
- python-version: 3.7
36-
django-version: 1.7.*
37-
defaults:
38-
run:
39-
shell: bash
22+
python-version: [ "3.7", "3.8", "3.9", "3.10" ]
23+
django-version: [ "3.2" ]
4024
steps:
4125
# Checks-out the repository.
4226
- uses: actions/checkout@v2
4327

4428
- name: Set up Python ${{ matrix.python-version }}
45-
uses: actions/setup-python@v2
29+
uses: actions/setup-python@v4
4630
with:
4731
python-version: ${{ matrix.python-version }}
32+
cache: 'pip'
33+
cache-dependency-path: |
34+
requirements.txt
35+
dev_requirements.txt
4836
4937
- name: Install Python dependencies
5038
run: |
@@ -56,5 +44,28 @@ jobs:
5644
run: pip install -e .
5745

5846
- name: Run tests
59-
run: python manage.py test
47+
run: |
48+
coverage run --source='../cache_helper' --data-file='../.coverage.${{ matrix.python-version }}.${{ matrix.django-version }}' manage.py test
6049
working-directory: ./test_project
50+
51+
- name: Create LCOV file
52+
run: |
53+
coverage lcov --data-file='.coverage.${{ matrix.python-version }}.${{ matrix.django-version }}'
54+
55+
- name: Coveralls Parallel
56+
uses: coverallsapp/github-action@master
57+
with:
58+
github-token: ${{ secrets.github_token }}
59+
flag-name: run-${{ matrix.python-version }}-${{ matrix.django-version }}
60+
path-to-lcov: coverage.lcov
61+
parallel: true
62+
63+
finish:
64+
needs: build
65+
runs-on: ubuntu-latest
66+
steps:
67+
- name: Coveralls Finished
68+
uses: coverallsapp/github-action@master
69+
with:
70+
github-token: ${{ secrets.github_token }}
71+
parallel-finished: true

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,7 @@
77
*.un~
88
.idea
99
build/
10+
*.egg-info
11+
.coverage
12+
**/htmlcov/**
13+
dist/*

.pre-commit-config.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v3.2.0
4+
hooks:
5+
- id: trailing-whitespace
6+
- id: end-of-file-fixer
7+
- id: check-added-large-files
8+
- id: check-ast
9+
10+
- repo: https://github.com/psf/black
11+
rev: 22.10.0
12+
hooks:
13+
- id: black

DEVELOPMENT.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Create Release
2+
3+
1. `rm -rf dist`
4+
1. Update version in `cache_helper/__init__.py`
5+
1. `pip install -r requirements.txt`
6+
1. `python -m build`
7+
1. `twine upload dist/*`

README.md

Lines changed: 68 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,84 @@
11
django-cache-helper
22
===================
33

4-
## Support
5-
**Python:** 3.4, 3.5, 3.6, 3.7
6-
7-
**Django:** 1.7, 1.8, 1.9, 1.10, 1.11, 2.0, 2.1, 2.2, 3.0
4+
 
5+
![PyPI](https://img.shields.io/pypi/v/django-cache-helper?color=green)
6+
[![Test Suite](https://github.com/ycharts/django_cache_helper/actions/workflows/main.yml/badge.svg?branch=master)](https://github.com/ycharts/django_cache_helper/actions/workflows/main.yml)
7+
[![Coverage Status](https://coveralls.io/repos/github/ycharts/django_cache_helper/badge.svg?branch=master)](https://coveralls.io/github/ycharts/django_cache_helper?branch=master)
88

99
## Overview
1010
django-cache-helper is a simple tool for making caching functions, methods, and class methods a little bit easier.
1111
It is largely based off of django-cache-utils, however, since cache-utils did not support caching model methods by instance and carried other features I didn't need, django-cache-helper was created.
1212

13-
In order to cache a function/method/class_method:
13+
In order to cache and invalidate a function/method/class_method/static_method:
14+
15+
## Support
16+
17+
| Python | Django |
18+
|--------|--------|
19+
| 3.7, 3.8, 3.9, 3.10 | 3.2 |
20+
21+
22+
#### How to Cache
1423

1524
```python
16-
@cached(60*60)
25+
# Caching a function
26+
@cached(60*60) # 60 Minutes
1727
def foo(bar):
1828
return bar
1929

20-
@property
21-
@cached(60*60)
22-
def foo(self):
23-
return self.id + 2
30+
class Incrementer:
31+
32+
@cached_instance_method(60 * 60)
33+
def instance_increment_by(self, num):
34+
return num
35+
36+
@classmethod
37+
@cached_class_method(60 * 60)
38+
def class_increment_by(cls, num):
39+
return num
40+
41+
@staticmethod
42+
@cached(60 * 60)
43+
def get_datetime():
44+
return datetime.utcnow()
2445
```
2546

47+
#### How to invalidate a cache
48+
49+
```python
50+
51+
foo(1)
52+
foo.invalidate(1)
53+
54+
Incrementer.instance_increment_by(1)
55+
Incrementer.instance_increment_by.invalidate(1)
56+
57+
Incrementer.class_increment_by(1)
58+
Incrementer.class_increment_by.invalidate(1)
59+
60+
Incrementer.get_datetime()
61+
Incrementer.get_datetime.invalidate()
62+
```
63+
64+
65+
## Contributors ✨
66+
67+
Thanks goes to these wonderful people.
68+
69+
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
70+
<!-- prettier-ignore-start -->
71+
<!-- markdownlint-disable -->
72+
<table>
73+
<tr>
74+
<td align="center"><img src="https://avatars.githubusercontent.com/u/2000316?v=4" width="100px;" alt="Kevin Fox"/><br /><sub><b>Kevin Fox</b></sub></td>
75+
<td align="center"><img src="https://avatars.githubusercontent.com/u/3022071?v=4" width="100px;" alt="Tom Jakeway"/><br /><sub><b>Tom Jakeway</b></sub></td>
76+
<td align="center"><img src="https://avatars.githubusercontent.com/u/83293?v=4" width="100px;" alt="Ara Anjargolian"/><br /><sub><b>Ara Anjargolian</b></sub></td>
77+
<td align="center"><img src="https://avatars.githubusercontent.com/u/15602942?v=4" width="100px;" alt="Hyuckin David Lim"/><br /><sub><b>Hyuckin David Lim</b></sub></td>
78+
<td align="center"><img src="https://avatars.githubusercontent.com/u/1248116?v=4" width="100px;" alt="James"/><br /><sub><b>James</b></sub></td>
79+
</tr>
80+
</table>
2681

82+
<!-- markdownlint-enable -->
83+
<!-- prettier-ignore-end -->
84+
<!-- ALL-CONTRIBUTORS-LIST:END -->

cache_helper/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
VERSION = (1, 0, 0)

cache_helper/decorators.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010

1111
from cache_helper import utils
1212

13-
def cached(timeout):
1413

14+
def cached(timeout):
1515
def _cached(func):
1616
func_name = utils.get_function_name(func)
1717

@@ -57,14 +57,15 @@ def invalidate(*args, **kwargs):
5757

5858

5959
def cached_class_method(timeout):
60-
6160
def _cached(func):
6261
func_name = utils.get_function_name(func)
6362

6463
@wraps(func)
6564
def wrapper(*args, **kwargs):
6665
# skip the first arg because it will be the class itself
67-
function_cache_key = utils.get_function_cache_key(func_name, args[1:], kwargs)
66+
function_cache_key = utils.get_function_cache_key(
67+
func_name, args[1:], kwargs
68+
)
6869
cache_key = utils.get_hashed_cache_key(function_cache_key)
6970

7071
try:

cache_helper/exceptions.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
class CacheHelperException(Exception):
22
pass
33

4+
45
class CacheKeyCreationError(CacheHelperException):
56
pass

0 commit comments

Comments
 (0)