karpetrosyan / hishel

An elegant HTTP Cache implementation for HTTPX and HTTP Core.
https://hishel.com
BSD 3-Clause "New" or "Revised" License
175 stars 22 forks source link

Support shared cache mode #224

Closed douglas-raillard-arm closed 3 months ago

douglas-raillard-arm commented 6 months ago

It seems that hishel is currently caching requests with the header Cache-Control: private without a toggle to turn that off.

The use-case is some sort of caching proxy server for my API. The proxy takes the clients request and forwards them to a central server. That request from the proxy to the central server is cached on the proxy side using hishel. Having a way to prevent caching of user-specific data inside the proxy could be useful if I end up with some at one point. Otherwise, the only solution would be to set no-store for them.

karpetrosyan commented 6 months ago

Oh, that's a great usage of hishel. I have never thought to use hishel in such a way.

I believe that would be simple to add; all we need is a new field in the Controller, such as cache_private, which can be true or false (true by default).

Also, we need to add a check for that field here: https://github.com/karpetrosyan/hishel/blob/5da601237f49b1d67caf695b7f8af32eaf27f8b3/hishel/_controller.py#L138

Simon-Will commented 4 months ago

I created a simple PR #251 that basically does what you suggested @karpetrosyan.