39 Commits

Author SHA1 Message Date
long2ice
5f985a8506 ci: fix 2024-07-24 22:24:30 +08:00
long2ice
8b5601cfdc Merge branch 'main' into fix-no-cache 2024-07-24 21:46:11 +08:00
Nik Stuckenbrock
552d54c1ca Fix redis example 2024-07-19 15:09:39 +02:00
Nik Stuckenbrock
63f9bdd068 Fix in memory example 2024-07-19 15:08:43 +02:00
John Lyu
74e827d3de fix tests 2024-05-09 14:51:58 +08:00
Martijn Pieters
230c24a4e0 Give tests and examples separate ruff configs (#158)
This allows more fine-grained lint rule adjustments, and allows
the examples to treat fastapi_cache as a 'third party' module, just
like users of the library would use it.
2023-05-16 12:42:12 +00:00
Martijn Pieters
d938bbe4d2 Add flake8-comprehensions linter (#157) 2023-05-16 12:18:53 +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
0763cd7b95 Add pyright strict type checking 2023-05-11 12:57:28 +01:00
Martijn Pieters
e92604802e Remove non-existing argument to unicorn.run 2023-05-11 12:31:07 +01:00
Martijn Pieters
013be85f97 Typing cleanup
- Compatibility with older Python versions
  - use `Optional` and `Union` instead of `... | None` and `a | b`
  - use `typing_extensions.Protocol` instead of `typing.Protocol`
  - use `typing.Dict`, `typing.List`, etc. instead of the concrete types.

- Fix backend `.get()` annotations; not all were marked as `Optional[str]`
- Don't return anything from `Backend.set()` methods.
- The `Coder.decode_as_type()` type parameter must be a type to be
  compatible with `ModelField(..., type_=...)`.
- Clean up `Optional[]` use, remove where it is not needed.
- Clean up variable use in decorator, keeping the raw cached value
  separate from the return value from the wrapped endpoint.
- Annotate the wrapper as returning either the original type _or_ a
  Response (returning a 304 Not Modified response).
- Clean up small edge-case where `response` could be `None`.
- Correct type annotation on `JsonCoder.decode()` to match `Coder.decode()`.
2023-05-11 12:31:05 +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
long2ice
59a47b7fae chore: set version 0.2.0 2023-01-11 21:20:41 +08:00
vvanglro
0d964fcf9f fix: remove unused 2023-01-07 13:55:41 +08: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
long2ice
566d30b790 Merge pull request #88 from vvanglro/feat/cache_html
feat: support cache jinja2 template response
2022-11-03 19:42:47 +08:00
Charl P. Botha
6ba06bb10f Fix sync example 2022-10-14 21:59:57 +02:00
Charl P. Botha
630b175766 Add tests for sync and disabled cache 2022-10-14 21:59:33 +02:00
Charl P. Botha
af9c4d4c56 Restore demo of sync handling 2022-10-14 13:44:59 +02:00
vvanglro
7e64cd6490 feat: support cache jinja2 template response 2022-09-28 17:37:05 +08:00
vvanglro
3dd4887b37 fix: example coroutine object is not iterable 2022-09-15 17:30:59 +08:00
long2ice
cb9259807e feat: make request and response optional 2022-09-10 20:06:37 +08:00
rtruran
70f5eed50b Merge branch 'master' into documentation 2022-08-08 08:16:24 -05:00
Jegor Kitskerkin
d6c52408d2 Add support for normal def functions 2022-08-01 00:06:39 +02:00
long2ice
824e2e145f Replace aioredis with redis-py 2022-06-17 11:01:47 +08:00
Ryan Truran
89826b0a3b added InMemory example 2022-02-24 10:07:33 -06:00
long2ice
c3be2eca19 Fix default json coder for datetime. 2021-10-09 16:51:05 +08:00
long2ice
46c7ada364 Fix ci 2021-07-26 16:37:19 +08:00
long2ice
767241be41 - Fix redis cache.
- Encode key builder.
2021-07-26 16:33:22 +08:00
long2ice
e483e0dc55 add clear method 2020-11-03 18:08:06 +08:00
long2ice
c0259bc699 Add in-memory support. 2020-10-08 15:10:34 +08:00
long2ice
c20bb73f27 first commit 2020-08-26 18:04:57 +08:00