obaki-local-storage
v0.0.5
Published
`obaki-local-storage` is a TypeScript utility for caching and retrieving data from the browser's `localStorage`. It provides a flexible and reusable function, allowing developers to cache data, automatically refresh it when needed, and define a custom st
Downloads
8
Readme
obaki-local-storage
obaki-local-storage
is a lightweight utility for efficient data caching and retrieval, designed to optimize performance by minimizing unnecessary network requests.
Installation
Install the package via npm:
npm install obaki-local-storage
Usage
getCacheData
import { getCacheData } from 'obaki-local-storage';
// Define your fetch data function
const fetchDataFunction = async () => {
// Implement your data fetching logic here
// ...
return /* fresh data */;
};
// Example usage for getCacheData
const cachedData = await getCacheData('my-cache-key', fetchDataFunction);
console.log('Cached Data:', cachedData);
getEncryptedCacheData
import { getEncryptedCacheData } from 'obaki-local-storage';
// Define your fetch data function
const fetchDataFunction = async () => {
// Implement your data fetching logic here
// ...
return /* fresh data */;
};
// Set your encryption key
const encryptionKey = 'your-secret-key';
// Example usage for getEncryptedCacheData
const encryptedData = await getEncryptedCacheData('my-encrypted-cache-key', fetchDataFunction, encryptionKey);
console.log('Encrypted Data:', encryptedData);
getEncryptedData
import { getEncryptedData } from 'obaki-local-storage';
const key = 'myEncryptedDataKey';
const encryptionKey = 'SuperSecretKey';
// Retrieve and decrypt data
const decryptedData = getEncryptedData(key, encryptionKey);
console.log('Decrypted Data:', decryptedData);
setEncryptedData
import { setEncryptedData } from 'obaki-local-storage';
const key = 'myEncryptedDataKey';
const encryptionKey = 'SuperSecretKey';
const dataToStore = ['confidential', 'information'];
// Encrypt and store data
setEncryptedData(key, dataToStore, encryptionKey);
console.log('Data encrypted and stored successfully.');