Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Improvement] useAsyncDataSource cache invalidation #994

Open
dellamonica opened this issue Sep 5, 2024 · 0 comments
Open

[Improvement] useAsyncDataSource cache invalidation #994

dellamonica opened this issue Sep 5, 2024 · 0 comments

Comments

@dellamonica
Copy link

It would be nice to be able to invalidate rows cached by the useAsyncDataSource hook.
My API suggestion would be to return an additional object in this hook, say a "cache" object, which encapsulates the internal cache and allows some control from the outside.

Perhaps this could be the type def for this cache:

interface AsyncDataSourceCache<TData> {
    /**
     * Gets the cached object (if there is any) for the given row.
     */
    get: (row: number) => TData | undefined
    /**
     * Invalidate the given cached rows, when no rows are specified, the entire cache is invalidated.
     */
    invalidate(rows?: number[]) => void
}

This allows easy access to cached row objects, which can come in handy when processing the grid events. It also allows invalidating any rows (say, by controlling their timestamp or whatever logic the client needs).

Currently, I have a component that needs this type of functionality and I had to resort to changing the component's key just to "clear" the internal state of the hook.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant