mercurius-js / cache

Adds an in-process caching layer to Mercurius. Federation is fully supported.
MIT License
106 stars 19 forks source link

feat: Support dynamic ttl function option #141

Closed agubler closed 1 year ago

agubler commented 1 year ago

Adds support for defining a dynamic ttl via a function in the cache options. This leverages the existing support for a dynamic ttl in https://github.com/mcollina/async-cache-dedupe.

Previously for redis when "invalidation" is enabled the referencesTTL is defaulted to the maximum ttl value from all the configuration values, this isn't possible with a dynamic ttl, as the function cannot be resolved until the function has been executed - for this scenario we use the maximum determinable ttl (if there is a least one static ttl defined) and where there are no static ttl option through an error stating that the referencesTTL option needs to be explicitly defined.

This includes some changes that were missing from #121 - namely policy level validation (and tests) plus the typings for stale - I can split this out into a separate pull request is required.

closes #137

cc @simone-sanfratello