Replies: 2 comments 3 replies
-
@DamianOsipiuk we need to think about this, too. It's not trpc related. For example, if you do search queries where the search term is part of the input, we will persist it under the key of what you searched for, but it will never be restored, and thus never cleared from storage, unless you explicitly search for the same thing again 🤔 |
Beta Was this translation helpful? Give feedback.
3 replies
-
Here is a very easy solution I've implemented. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Issue Description:
Summary:
We are currently implementing tRPC and TanStack Query in our project, utilizing the experimental
createPersister
feature. While the integration works well, we've encountered an issue with the accumulation of outdated data in the storage, which TanStack Query does not automatically delete.Detailed Explanation:
Our implementation includes a
user.byUsername
route in tRPC with a fixed query key structure (user
,byUsername
, and the username as input). When a username is changed in theuser.byUsername
endpoint, the query key also changes accordingly (or just another profile was opened with a different username). This results in the persistence of both the old and new entries in the storage. Since TanStack Query no longer calls the old key (unless it happens randomly someday), it remains indefinitely in the storage. This data persists until it is manually deleted, or the storage is cleared by the system due to space constraints, or further writing to AsyncStorage/LocalStorage is restricted.Core Issue:
The main concern is the unmanaged growth of old data in the storage, leading to potential overflow and inefficiency. The current behavior of
experimental_createPersister
only writes cache to memory when it is accessed, which means old, unused entries are not addressed.Suggested Solution:
A potential solution could involve TanStack Query performing a cache validation process on boot. This process would scan through the cache to identify and delete old, expired keys. However, this approach might need to be carefully designed to avoid significant performance impacts, especially for applications with large caches.
Request:
We are seeking advice or a potential update in TanStack Query to handle this scenario more efficiently. An automated mechanism to clean up old, unused data in the storage would greatly enhance the usability and reliability of the persistence feature, especially for applications with dynamic query keys like ours.
Beta Was this translation helpful? Give feedback.
All reactions