Skip to content
Merged

v2 #2

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 67 additions & 4 deletions .github/workflows/ci-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
- lint
strategy:
matrix:
python: ["3.12", "3.13"]
python: [ "3.12", "3.13" ]
fail-fast: false

name: "Test on Python ${{ matrix.python }}"
Expand All @@ -63,7 +63,7 @@ jobs:
test-summary:
name: Test matrix status
runs-on: ubuntu-latest
needs: [test]
needs: [ test ]
if: always()
steps:
- name: Decide whether the needed jobs succeeded or failed
Expand All @@ -74,7 +74,7 @@ jobs:
build:
name: Build distributions
runs-on: ubuntu-latest
needs: [test-summary]
needs: [ test-summary ]
steps:
- name: Checkout
uses: actions/checkout@v4
Expand All @@ -92,10 +92,40 @@ jobs:
name: dist
path: dist

update-changelog:
name: Update CHANGELOG.md
runs-on: ubuntu-latest
needs: [ build ]
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Generate changelog
uses: orhun/git-cliff-action@v4
with:
config: pyproject.toml
args: --verbose
env:
OUTPUT: CHANGELOG.md
GITHUB_REPO: ${{ github.repository }}

- name: Commit
run: |
git checkout ${{ github.ref_name }}
git config user.name 'github-actions[bot]'
git config user.email 'github-actions[bot]@users.noreply.github.com'
set +e
git add CHANGELOG.md
git commit -m "chore(changelog): Update changelog"
git push https://${{ secrets.GITHUB_TOKEN }}@github.com/${GITHUB_REPOSITORY}.git ${{ github.ref_name }}

publish:
name: Build and publish Python 🐍 distributions 📦 to PyPI
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
needs: [build]
needs: [ build ]
runs-on: ubuntu-latest
environment:
name: pypi
Expand All @@ -112,3 +142,36 @@ jobs:
path: dist
- name: Publish distribution 📦 to PyPI
uses: pypa/gh-action-pypi-publish@release/v1

release:
name: Create Github Release
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
needs: [ publish ]
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Generate a changelog
uses: orhun/git-cliff-action@v4
id: git-cliff
with:
config: pyproject.toml
args: -vv --latest --strip header
env:
OUTPUT: CHANGELOG.md
GITHUB_REPO: ${{ github.repository }}

- name: Download artifacts
uses: actions/download-artifact@v4
with:
name: dist
path: dist

- name: Upload the binary releases
uses: softprops/action-gh-release@v2
with:
files: |
dist/*
body: ${{ steps.git-cliff.outputs.content }}
37 changes: 37 additions & 0 deletions .github/workflows/git-cliff.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Changelog
on:
pull_request:
types:
- opened
- reopened
- synchronize
- labeled
- unlabeled
branches:
- main

jobs:
git_cliff:
name: Git Cliff
runs-on: ubuntu-latest
# skip if this is a bot or the PR has the skip-changelog label
# note that the towncrier check command can recognize a release PR, by looking
# for changes to the CHANGELOG.md file.
if: |
!(
github.event.pull_request.user.login == 'dependabot[bot]'
|| contains(github.event.pull_request.labels.*.name, 'skip-changelog')
)
steps:
- name: Check out repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Generate a changelog
uses: orhun/git-cliff-action@v3
with:
config: pyproject.toml
args: --verbose
env:
OUTPUT: CHANGELOG.md
GITHUB_REPO: ${{ github.repository }}
54 changes: 0 additions & 54 deletions .github/workflows/towncrier.yml

This file was deleted.

78 changes: 16 additions & 62 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,80 +1,34 @@
# ChangeLog
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

This project uses [_towncrier_](https://towncrier.readthedocs.io/) and the changes for the upcoming release can be found in <https://github.com/Yolley/fastapi-cache/tree/main/changelog.d/>.
This project uses [git-cliff](https://git-cliff.org/).

<!-- towncrier release notes start -->
## [1.0.3] - 2025-04-29

## 0.2
### 💼 Other

### 0.2.1
- Set cache ctx right at the beginning
- Bump

- Fix picklecoder
- Fix connection failure transparency and add logging
- Add Cache-Control and ETag on first response
- Support Async RedisCluster client from redis-py
## [1.0.2] - 2025-04-29

### 0.2.0
### 🚜 Refactor

- Make `request` and `response` optional.
- Add typing info to the `cache` decorator.
- Support cache jinja2 template response.
- Support cache `JSONResponse`
- Add `py.typed` file and type hints
- Add TestCase
- Fix cache decorate sync function
- Transparently handle backend connection failures.
- Refactor, remove excessive print

## 0.1
## [1.0.1] - 2025-04-29

### 0.1.10
### 💼 Other

- Add `Cache-Control:no-cache` support.
- Update ruff, optimise no cache

### 0.1.9
## [1.0.0] - 2025-04-29

- Replace `aioredis` with `redis-py`.
### 🚜 Refactor

### 0.1.8
- Refactor decorator, add cache context, drop py3.11, add py3.13

- Support `dynamodb` backend.

### 0.1.7

- Fix default json coder for datetime.
- Add `enable` param to `init`.

### 0.1.6

- Fix redis cache.
- Encode key builder.

### 0.1.5

- Fix setting expire for redis (#24)
- Update expire key

### 0.1.4

- Fix default expire for memcached. (#13)
- Update default key builder. (#12)

### 0.1.3

- Fix cache key builder.

### 0.1.2

- Add default config when init.
- Update JsonEncoder.

### 0.1.1

- Add in-memory support.

### 0.1.0

- First version release.
<!-- generated by git-cliff -->
1 change: 0 additions & 1 deletion changelog.d/172.feature.md

This file was deleted.

15 changes: 0 additions & 15 deletions changelog.d/changelog_template.jinja

This file was deleted.

9 changes: 5 additions & 4 deletions examples/in_memory/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
import pendulum
import uvicorn
from fastapi import FastAPI
from fastapi_cache import FastAPICache, get_cache_ctx
from fastapi_cache.backends.inmemory import InMemoryBackend
from fastapi_cache.decorator import cache
from pydantic import BaseModel
from starlette.requests import Request
from starlette.responses import JSONResponse, Response

from fastapi_cache import FastAPICache, get_cache_ctx
from fastapi_cache.backends.inmemory import InMemoryBackend
from fastapi_cache.decorator import cache


@asynccontextmanager
async def lifespan(_: FastAPI) -> AsyncIterator[None]:
Expand Down Expand Up @@ -167,7 +168,7 @@ async def cached_with_ctx(update_expire: bool = True):

ctx = get_cache_ctx()
if update_expire:
ctx["expire"] = 3_600
ctx.expire = 3_600
put_ret5 = put_ret5 + 1
return {"value": put_ret5}

Expand Down
10 changes: 5 additions & 5 deletions examples/redis/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
from fastapi.responses import HTMLResponse
from fastapi.staticfiles import StaticFiles
from fastapi.templating import Jinja2Templates
from fastapi_cache import FastAPICache, get_cache_ctx
from fastapi_cache.backends.redis import RedisBackend
from fastapi_cache.coder import PickleCoder
from fastapi_cache.decorator import cache
from starlette.requests import Request
from starlette.responses import JSONResponse, Response

import redis.asyncio as redis
from fastapi_cache import FastAPICache, get_cache_ctx
from fastapi_cache.backends.redis import RedisBackend
from fastapi_cache.coder import PickleCoder
from fastapi_cache.decorator import cache
from redis.asyncio.connection import ConnectionPool


Expand Down Expand Up @@ -99,7 +99,7 @@ async def cache_with_lock():
async def cache_with_ctx():
ctx = get_cache_ctx()

ctx["expire"] = 300
ctx.expire = 300
return {"result": 42}


Expand Down
Loading