hapijs / joi

The most powerful data validation library for JS
Other
20.86k stars 1.51k forks source link

Caching for strings / numbers / booleans #1727

Closed maikelmclauflin closed 5 years ago

maikelmclauflin commented 5 years ago

Describe the problem you are trying to fix (provide as much context as possible)

with complex string checking like regex, especially when there are many at the bottom of objects, it may make more sense to cache results of schema if this is not being done to decrease execution time.

Which API (or modification of the current API) do you suggest to solve that problem ?

anything that checks a non object / non array / serializable data structure for the first part, to optionally speed up large object values that generally do not change over time. cache could be scoped to the validator itself or to an identity created by the validator

Are you ready to work on a pull request if your suggestion is accepted ?

yes

hueniverse commented 5 years ago

The hard part isn't the caching but memory management. Need to create something that is effective but that does not create potential problems with an ever growing map of values to results. I think starting with a plugable API that lets you hook a cache into validation seems best. I'll try to come up with something.