kalekundert / byoc

MIT License
0 stars 0 forks source link

Configure caching on a per-key basis #18

Closed kalekundert closed 2 years ago

kalekundert commented 3 years ago

For example, I might want to recalculate an attribute each time if its value involves a Method key, since that could depend on other attributes of the object, but cache the attribute if it involves any other key. Note that this depends on which values are actually used; e.g. consumed by the pick() generator. Key should take its default caching behavior from the configs it matches, so that static configs can be cached by default while potentially dynamic configs can be looked up every time.

The API would be straight-forward:

x = appcli.param(
        Key(MyConfig, 'x', dynamic=False),
)
kalekundert commented 3 years ago

On the topic of caching, I'm also wondering if would be possible to implement @cached_property-style caching, e.g. where the cached value is written to the instance dictionary such that it shadows the descriptor and can be read/written with no performance penalty.

Some thoughts on how to do this:

I can't completely get rid or the get and set arguments, though. SWMB uses get a lot, in particular for binding arguments. set is less used, but goes hand-in-hand with get.

kalekundert commented 2 years ago

Pseudo-code implementation: