Commit Graph

23 Commits

Author SHA1 Message Date
Gary Gale
b2e7bad0bb test #459: fix failing datetime and date logic tests 2025-01-17 16:20:43 +00:00
long2ice
5f985a8506 ci: fix 2024-07-24 22:24:30 +08:00
John Lyu
74e827d3de fix tests 2024-05-09 14:51:58 +08:00
John Lyu
6f8994b843 fix test 2024-05-09 14:43:53 +08:00
John Lyu
e4a0df62dd fix #424, no-cache should store the result to cache 2024-05-09 14:32:02 +08:00
Martijn Pieters
23bb4e9cd4 Add pytest-style linting (#159)
This does mean we need to tell pyright that the init_cache auto-use
fixture is still being used even though it now has a leading underscore.
2023-05-16 12:45:26 +00:00
Martijn Pieters
1d9e126037 Switch to ruff to handle linting and formatting
Ruff handles black, flake8 and isort in one package, and is way faster.
The isort rules had not been enforced, so this commit includes a lot
of import resorting changes.

I switched to flake8-bugbear and the standard black-compatible line
length of 80 + 10% (so max 88 characters), so some line reflowing is
included too.

Finally, because bugbear rightly points out that `setattr()` is less
performant, I've switched the `__signature__` assigment back to using
a direct assignment with type ignore comment.
2023-05-16 12:18:24 +01:00
Martijn Pieters
915f3dd8f2 Add a cache status header to the response
The header name is configurable, and defaults to `X-FastAPI-Cache`,
the value is either `HIT` or `MISS`.

Note that the header is not set at all when the cache is disabled.
2023-05-14 17:03:57 +01:00
Martijn Pieters
0763cd7b95 Add pyright strict type checking 2023-05-11 12:57:28 +01:00
Martijn Pieters
941cd044c7 Full mypy --strict type checking pass 2023-05-11 12:34:08 +01:00
Martijn Pieters
e09ede2e4c Inject dependencies using a namespace
Instead of assuming that the Request and Response injected keyword
arguments can be named `request` and `response`, use namespaced
keyword names starting with a double underscore.

By default the parameter names now start with `__fastapi_cache_` and so
are a) clearly marked as internal, and b) highly unlikely to clash with
existing keyword arguments. The prefix is configurable in the unlikely
event that the names would clash in specific cases.
2023-05-09 11:09:29 +01:00
Martijn Pieters
4cc946eb00 Fix handling non-GET requests
The `request` parameter being passed in was just a hold-over from an
earlier refactoring. Added tests to ensure that this edge case keeps
working.
2023-05-09 10:58:37 +01:00
Martijn Pieters
f78a599bbc Decode cache data to the correct endpoint type
Use the return annotation to decode cached data to the correct type.
This follows the same logic FastAPI uses to JSON request bodies.

For the PickleCoder, this is a no-op as pickle already stores type
information in the serialised data.
2023-05-08 16:55:05 +01:00
Martijn Pieters
832650347b Attach updated endpoint signature to inner
Not all endpoints accept a __signature__ attribute, nor should the
cache decorator modify the decorated endpoint. Attach the signature
to the returned inner function instead.

While here, refactor the signature updating code, and extract it to
a separate function.
2023-04-27 18:14:59 +01:00
long2ice
27acce3160 ci: fix poetry 2023-02-15 10:45:19 +08:00
Naoki Shima
98cf8a78a1 adding test coverage 2023-02-15 10:35:41 +09:00
vvanglro
614ee25d0d feat: merge master 2023-01-07 13:46:48 +08:00
long2ice
8f0920d0d7 ci: fix 2022-11-07 16:39:17 +08:00
vvanglro
2710129c4e feat: cache response obj add test case 2022-11-04 17:34:20 +08:00
Ivan Moiseev
c6bd8483a4 feat: fix tests and add FastAPICache init in tests. 2022-10-22 21:12:04 +04:00
Charl P. Botha
630b175766 Add tests for sync and disabled cache 2022-10-14 21:59:33 +02:00
long2ice
cb9259807e feat: make request and response optional 2022-09-10 20:06:37 +08:00
long2ice
c20bb73f27 first commit 2020-08-26 18:04:57 +08:00