You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'd like to make it easy to load cache settings from a config file, without being tied to a specific format. CacheSettings is already an attrs class, and can be easily loaded from a dict, so that gets us most of the way there. Other validators or converters could be added to that if needed. There is some basic example code and config in the docs for using this with yaml.
Current limitations
The main limitation is that you can't put python expressions in a json/toml/yaml file. Right now (as of 1.0) there are 3 main things you can pass to CacheSettings that don't translate to config file primitive types:
Custom callback functions: Trying to fit that into a config file sounds like a terrible idea, so I'm not going to go there!
Expiration timedelta objects: This could be handled in your own library by parsing time expression strings (like @glensc mentioned here). The pytimeparse library is a good way to handle that.
EXPIRE_IMMEDIATELY / 0: Same meaning as Cache-Control: max-age=0. It's probably fine to just put 0 in config.
NEVER_EXPIRE / -1: No expiration. It's also probably fine to put -1 in config, but it's an arbitrary value, and it isn't immediately obvious what it means. I don't like the idea of using None, since that's ambiguous (could mean either "no expiration" or "no value; use default").
DO_NOT_CACHE: Another non-standard, arbitrary value to skip both cache read and write, with no exceptions (unlike max-age=0, no-cache, etc.). This could potentially be written in config as no-store, since that's the closest standard Cache-Control value.
Ideally, a config file should make sense to someone reading it on its own without needing to know all the details of requests-cache's settings. The constants NEVER_EXPIRE and DO_NOT_CACHE are the main things that currently don't translate well to a config file.
Feedback needed
Does anyone else have thoughts on this? For example, for a python snippet like this:
I'd like to make it easy to load cache settings from a config file, without being tied to a specific format. CacheSettings is already an
attrs
class, and can be easily loaded from a dict, so that gets us most of the way there. Other validators or converters could be added to that if needed. There is some basic example code and config in the docs for using this with yaml.Current limitations
The main limitation is that you can't put python expressions in a json/toml/yaml file. Right now (as of 1.0) there are 3 main things you can pass to
CacheSettings
that don't translate to config file primitive types:timedelta
objects: This could be handled in your own library by parsing time expression strings (like @glensc mentioned here). The pytimeparse library is a good way to handle that.EXPIRE_IMMEDIATELY
/0
: Same meaning asCache-Control: max-age=0
. It's probably fine to just put0
in config.NEVER_EXPIRE
/-1
: No expiration. It's also probably fine to put-1
in config, but it's an arbitrary value, and it isn't immediately obvious what it means. I don't like the idea of usingNone
, since that's ambiguous (could mean either "no expiration" or "no value; use default").DO_NOT_CACHE
: Another non-standard, arbitrary value to skip both cache read and write, with no exceptions (unlikemax-age=0
,no-cache
, etc.). This could potentially be written in config asno-store
, since that's the closest standard Cache-Control value.Ideally, a config file should make sense to someone reading it on its own without needing to know all the details of requests-cache's settings. The constants
NEVER_EXPIRE
andDO_NOT_CACHE
are the main things that currently don't translate well to a config file.Feedback needed
Does anyone else have thoughts on this? For example, for a python snippet like this:
What should that look like in yaml format?
The text was updated successfully, but these errors were encountered: