data-provider/core

Options for cache expiration time

Closed this issue · 0 comments

It is desirable to add a cacheTime option to the Provider Class. This option may define the maximum time the cache is valid, and, next time the provider is read, it would be ignored.

With this method, the cache is not cleaned automatically under the hood, it will only be ignored when the read method is dispatched and the time has expired. So, for example, if you have a React component connected to a data provider using the @data-provider/react useData hook, the data will not be refreshed until you rerender the component, because the cleanCache event is not being triggered.

Another method could be useful too: cleanCacheInterval.

With this method, the cache is automatically cleaned every defined interval, and the cleanCache will be triggered, so every alive connected component or dependant selector will be automatically read again, and the data will be refreshed without the need to manually dispatch the read method.