UNPKG

atikin-hyper-cachex

Version:

Intelligent caching for Node.js applications, leveraging AI to predict frequently accessed data.

33 lines (25 loc) 847 B
const redis = require('redis'); const { MongoClient } = require('mongodb'); const { Pool } = require('pg'); const dotenv = require('dotenv'); dotenv.config(); const redisClient = redis.createClient({ url: process.env.REDIS_URL }); const mongoClient = new MongoClient(process.env.MONGO_URI); const pgPool = new Pool({ connectionString: process.env.POSTGRES_URI }); (async () => { await redisClient.connect(); await mongoClient.connect(); })(); const cacheManager = { async set(key, value, ttl = 3600) { await redisClient.setEx(key, ttl, JSON.stringify(value)); }, async get(key) { const value = await redisClient.get(key); return value ? JSON.parse(value) : null; }, async delete(key) { await redisClient.del(key); }, }; module.exports = { cacheManager, mongoClient, pgPool };