Caching in Node.js to optimize app performance
npm install lzo-hyperc OR yarn add lzo-hyperc
Please input the credentials of your Redis server in the .env
file.
See the example in the
.env.example
file.
REDIS_URL="redis://IP:PORT"
REDIS_PORT=6379
REDIS_PASSWORD="PASSWORD"
import { Hyperc } from 'lzo-hyperc';
await Hyperc.create('test', 1000); // Create a cache with a 1 second TTL
await Hyperc.set('test', 'name', 'John Doe'); // Set a value in the cache
await Hyperc.get('test', 'name'); // John Doe
setTimeout(() => {
cache.get('test', 'name').then(console.log); // null (cache expired)
}, 1000);
Hyperc.create(identifier: string | number, ttl: number): Promise<boolean>
Create a cache with a TTL.
Hyperc.set<T>(identifier: string | number, key: string, value: T): Promise<boolean>
Set a value in the cache.
Hyperc.get<T>(identifier: string | number, key: string): Promise<T | null>
Get a value from the cache.
Hyperc.del(identifier: string | number, key: string): Promise<boolean>
delete a value in the cache.
Hyperc.flush(identifier: string | number): Promise<boolean>
Flush the cache by identifier.
Hyperc.flushAll(): Promise<boolean>
Flush all caches.
Support this project by becoming a sponsor.
Licensed under the MIT. See the LICENSE file for details.