fastapi-cache icon indicating copy to clipboard operation
fastapi-cache copied to clipboard

Add no-store, no-cache in Cache-Control headers

Open Bharat23 opened this issue 2 years ago • 23 comments

Changes

  • Removed the logic to never use cache if either of no-cache/no-store was present
  • Instead they work as follows
  • no-cache: doesn't use cache even if the value is present but stores the response in the cache
  • no-store: can use cache if present but will not add/update to cache
  • If both are passed, it will neither store nor use the cache. Will remove the max-age and ETag as well.
  • Test cases

Associated Issue: https://github.com/long2ice/fastapi-cache/issues/144

Bharat23 avatar Jan 10 '24 04:01 Bharat23

Can I do something to help merging the PR ? I need it in one of my project.

zozoh94 avatar Jul 04 '24 15:07 zozoh94

Can I do something to help merging the PR ? I need it in one of my project.

@zozoh94 the owner @long2ice seems to be inactive. Probably adding more 👍 (+1) to the PR by community will help.

Bharat23 avatar Jul 06 '24 20:07 Bharat23

Hey @long2ice do you have time to review and push thru this fix please?

sultaniman avatar Sep 02 '24 09:09 sultaniman

Thanks! Please resolve conflicts.

long2ice avatar Sep 02 '24 09:09 long2ice

@Bharat23 @zozoh94 can anyone rebase and resolve conflicts?

sultaniman avatar Sep 02 '24 11:09 sultaniman

Thanks! Please resolve conflicts.

@long2ice resolved the conflict.

Bharat23 avatar Sep 07 '24 22:09 Bharat23

@long2ice can you please take a look again?

sultaniman avatar Sep 11 '24 13:09 sultaniman

Thanks!

long2ice avatar Sep 11 '24 13:09 long2ice

@Bharat23 @zozoh94 I think we need to make tests pass, thanks to @long2ice for enabling auto merge.

sultaniman avatar Sep 11 '24 15:09 sultaniman

@Bharat23 @zozoh94 I think we need to make tests pass, thanks to @long2ice for enabling auto merge.

I'll take care of them.

Bharat23 avatar Sep 11 '24 19:09 Bharat23

Thanks @Bharat23

sultaniman avatar Sep 11 '24 19:09 sultaniman

@Bharat23 @zozoh94 I think we need to make tests pass, thanks to @long2ice for enabling auto merge.

@sultaniman @long2ice Had to alter and remove some test cases as they were breaking due to the change introduced in this PR

Bharat23 avatar Sep 11 '24 20:09 Bharat23

@long2ice can you please check again once you have time?

sultaniman avatar Sep 18 '24 11:09 sultaniman

@Bharat23 can you please ignore mypy warnings for line 26 and 30 in tests/test_decorator.py, I can't push changes into your repo, otherwise I would do it.

sultaniman avatar Sep 19 '24 11:09 sultaniman

@Bharat23 can you please ignore mypy warnings for line 26 and 30 in tests/test_decorator.py, I can't push changes into your repo, otherwise I would do it.

@sultaniman I didn't understand. I am not seeing any mypy issue on 26 and 30. Can you point me to how/where I can see that and what specific error should I ignore?

Bharat23 avatar Sep 20 '24 03:09 Bharat23

@Bharat23 I meant the linter failed in test/test_decorator.py I suggested to use per line ignore instead of a global ignore.

sultaniman avatar Sep 20 '24 08:09 sultaniman

@Bharat23 I meant the linter failed in test/test_decorator.py I suggested to use per line ignore instead of a global ignore.

@sultaniman done

Bharat23 avatar Sep 21 '24 21:09 Bharat23

@sultaniman @long2ice, can we get this merged please? Thanks

Bharat23 avatar Oct 01 '24 15:10 Bharat23

I would also be happy to get this PR done, only @long2ice can merge it.

sultaniman avatar Oct 02 '24 07:10 sultaniman

@Bharat23 looks like the datetime dependency has minor upgrade and it no longer has to_atom_string method

/home/runner/work/fastapi-cache/fastapi-cache/tests/test_decorator.py
  /home/runner/work/fastapi-cache/fastapi-cache/tests/test_decorator.py:37:16 - error: Type of "to_atom_string" is partially unknown
    Type of "to_atom_string" is "Unknown | (() -> str)" (reportUnknownMemberType)
  /home/runner/work/fastapi-cache/fastapi-cache/tests/test_decorator.py:37:20 - error: Cannot access attribute "to_atom_string" for class "Date"
    Attribute "to_atom_string" is unknown (reportAttributeAccessIssue)
  /home/runner/work/fastapi-cache/fastapi-cache/tests/test_decorator.py:37:20 - error: Cannot access attribute "to_atom_string" for class "Time"
    Attribute "to_atom_string" is unknown (reportAttributeAccessIssue)
  /home/runner/work/fastapi-cache/fastapi-cache/tests/test_decorator.py:37:20 - error: Cannot access attribute "to_atom_string" for class "Duration"
    Attribute "to_atom_string" is unknown (reportAttributeAccessIssue)
4 errors, 0 warnings, 0 informations 
WARNING: there is a new pyright version available (v1.1.381 -> v1.1.383).

sultaniman avatar Oct 02 '24 13:10 sultaniman

@Bharat23 looks like the datetime dependency has minor upgrade and it no longer has to_atom_string method

/home/runner/work/fastapi-cache/fastapi-cache/tests/test_decorator.py
  /home/runner/work/fastapi-cache/fastapi-cache/tests/test_decorator.py:37:16 - error: Type of "to_atom_string" is partially unknown
    Type of "to_atom_string" is "Unknown | (() -> str)" (reportUnknownMemberType)
  /home/runner/work/fastapi-cache/fastapi-cache/tests/test_decorator.py:37:20 - error: Cannot access attribute "to_atom_string" for class "Date"
    Attribute "to_atom_string" is unknown (reportAttributeAccessIssue)
  /home/runner/work/fastapi-cache/fastapi-cache/tests/test_decorator.py:37:20 - error: Cannot access attribute "to_atom_string" for class "Time"
    Attribute "to_atom_string" is unknown (reportAttributeAccessIssue)
  /home/runner/work/fastapi-cache/fastapi-cache/tests/test_decorator.py:37:20 - error: Cannot access attribute "to_atom_string" for class "Duration"
    Attribute "to_atom_string" is unknown (reportAttributeAccessIssue)
4 errors, 0 warnings, 0 informations 
WARNING: there is a new pyright version available (v1.1.381 -> v1.1.383).

@sultaniman the method exists, this is a mypy issue. There is a mismatch between how the local vs github workflow env is configured because they contradict each other. Ultimately I had to add 2 ignores to satisfy both. Hopefully this is the last commit before this can be merged.

Bharat23 avatar Oct 13 '24 00:10 Bharat23

@Bharat23 @sultaniman Just looking at this PR now ... as it's a change to existing behaviour I'm minded to roadmap this for 1.0.0 which I'll be working on as soon as 0.3.0 is out the door. But happy to be persueded otherwise

vicchi avatar Nov 11 '24 09:11 vicchi

+1; this brings the package in line with the RFC.

ermiyaeskandary avatar Dec 28 '24 21:12 ermiyaeskandary