Security News
New Python Packaging Proposal Aims to Solve Phantom Dependency Problem with SBOMs
PEP 770 proposes adding SBOM support to Python packages to improve transparency and catch hidden non-Python dependencies that security tools often miss.
@tanstack/query-sync-storage-persister
Advanced tools
A persister for synchronous storages, to be used with TanStack/Query
@tanstack/query-sync-storage-persister is a package designed to persist TanStack Query cache data to various storage solutions, such as localStorage or sessionStorage. This allows for the state of queries to be saved and restored, providing a more seamless user experience across sessions.
Persisting Query Cache to Local Storage
This feature allows you to persist the query cache to the local storage. The code sample demonstrates how to set up the persister with localStorage and integrate it with the TanStack Query client.
const { persistQueryClient } = require('@tanstack/query-sync-storage-persister');
const { QueryClient, QueryCache } = require('@tanstack/react-query');
const { createSyncStoragePersister } = require('@tanstack/query-sync-storage-persister');
const queryClient = new QueryClient({
queryCache: new QueryCache(),
});
const localStoragePersister = createSyncStoragePersister({
storage: window.localStorage,
});
persistQueryClient({
queryClient,
persister: localStoragePersister,
});
Persisting Query Cache to Session Storage
This feature allows you to persist the query cache to the session storage. The code sample demonstrates how to set up the persister with sessionStorage and integrate it with the TanStack Query client.
const { persistQueryClient } = require('@tanstack/query-sync-storage-persister');
const { QueryClient, QueryCache } = require('@tanstack/react-query');
const { createSyncStoragePersister } = require('@tanstack/query-sync-storage-persister');
const queryClient = new QueryClient({
queryCache: new QueryCache(),
});
const sessionStoragePersister = createSyncStoragePersister({
storage: window.sessionStorage,
});
persistQueryClient({
queryClient,
persister: sessionStoragePersister,
});
redux-persist is a library used to persist and rehydrate a Redux store. It provides similar functionality in terms of persisting state to storage solutions like localStorage or sessionStorage. However, it is designed specifically for Redux, whereas @tanstack/query-sync-storage-persister is designed for TanStack Query.
localforage is a library that provides a simple API for storing data in various storage solutions, including IndexedDB, WebSQL, and localStorage. While it is not specifically designed for persisting query caches, it can be used in conjunction with other libraries to achieve similar functionality.
idb-keyval is a small library for storing key-value pairs in IndexedDB. It is a lower-level solution compared to @tanstack/query-sync-storage-persister, which is specifically designed for persisting TanStack Query caches. idb-keyval can be used as a building block for more complex persistence solutions.
FAQs
A persister for synchronous storages, to be used with TanStack/Query
We found that @tanstack/query-sync-storage-persister demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
PEP 770 proposes adding SBOM support to Python packages to improve transparency and catch hidden non-Python dependencies that security tools often miss.
Security News
Socket CEO Feross Aboukhadijeh discusses open source security challenges, including zero-day attacks and supply chain risks, on the Cyber Security Council podcast.
Security News
Research
Socket researchers uncover how threat actors weaponize Out-of-Band Application Security Testing (OAST) techniques across the npm, PyPI, and RubyGems ecosystems to exfiltrate sensitive data.