React Caches
React Caches is a lightweight and easy-to-use package that simplifies the management of local storage and cache storage in your React-based applications. With this package, you can easily access and manage data stored in local storage, cache storage, and other local storage used by JavaScript. It provides a convenient interface to store and retrieve data, making it seamless to work with client-side storage in your React projects.
Features
- Simplified access to local storage: Easily store and retrieve data in local storage using simple APIs.
- Cache storage management: Manage cache storage with straightforward methods, allowing you to handle data caching effortlessly.
- Integration with React: Designed to work smoothly with React applications, enabling you to enhance data handling on the client-side.
- Lightweight: The package is lightweight, ensuring it doesn't introduce unnecessary overhead to your application.
- Easy to use: The package offers intuitive APIs, making it user-friendly for developers of all levels.
Installation
To install the package, run the following command:
npm install react-caches@latest
Usage
# Cache Storage
To use the cache storage features, import the CacheStorage Related Functions from the package:
import { CacheStorage } from "react-caches";
const CacheStorage = new CacheStorage("DatabaseName");
const { receiveCache, saveCacheData, deleteCache, updateCache, clearCache } =
CacheStorage;
const Data = await receiveCache("Searchkey");
const Response = await saveCacheData("Searchkey", Data);
const Response = await deleteCache("Searchkey");
const Response = await updateCache("Searchkey", Data);
const Response = await clearCache();
Local Storage
To use the local storage features, import the Local Storage Related Functions from the package:
import { LocalStorage } from "react-caches";
const {
getLocalStorageData,
saveLocalStorageData,
removeLocalStorageData,
updateLocalStorageData,
clearLocalStorageData,
} = LocalStorage;
const Data = getLocalStorageData("Searchkey");
const Response = saveLocalStorageData("Searchkey", Data);
const Response = removeLocalStorageData("Searchkey");
const Response = updateLocalStorageData("Searchkey", Data);
const Response = clearLocalStorageData();
Session Storage
To use the session storage features, import the Session Storage Related Functions from the package:
import { SessionStorage } from "react-caches";
const {
getSessionData,
saveSessionData,
removeSessionData,
updateSessionData,
clearSessionData,
} = SessionStorage;
const Data = getSessionData("Searchkey");
const Response = saveSessionData("Searchkey", Data);
const Response = removeSessionData("Searchkey");
const Response = updateSessionData("Searchkey", Data);
const Response = clearSessionData();
IndexedDB
To use the IndexedDB features, import the IndexedDB Related Functions from the package, Remember that IndexedDB is an object-oriented database, so you need to create a database and object store before using it:
import { IndexedDB } from 'react-caches';
const {createData, readData, updateData, deleteData} = new IndexedDB('DatabaseName', 'Database Version' 'ObjectStoreName');
const Response = await createData('Searchkey', Data);
const Data = await readData('Searchkey');
const Response = await updateData('Searchkey', Data);
const Response = await deleteData('Searchkey');
Encryption - Decryption
If You Want to Use Encrypt and Decrypt, You Need To Install in your Server Side
npm i outers@latest --save
const {React as Service} = require('react-caches');
const Crypto = new Service.ClassBasedFunctions.ReactEncrypt("Key");
const EncryptedData = await Crypto.Encrypt("Data");
const DecryptedData = await Crypto.Decrypt("EncryptedData");