0

Using Caching to pull the Data from SQL server

Hallo ! In this code I pull the data "Products" from SQL server and calculate the time the request takes to get all the products. The question is, how can I do the same task, but using "the cache" by adding it by redis ?......................... Noting that I saw an example explaining how to retrieve data from the net using Caching, but I want to get it from the SQL server not from net, how can I do that? and this is my code: productController.js: const Product = require('../Models/productModel'); const express=require('express'); const takeData = async(req, res) => { const dbResult =await Product.findAll(req.Product) const allProducts = dbResult.recordset; return res.status(200).json({message: '', products: allProducts}) } module.exports = { takeData:takeData } productModel.js: const UniqueId = require('uniqid'); const SingletonSqlHandler = require('../SQLServer/singleton'); class Product { constructor(ProductName, Price) { this.ProductID = UniqueId(); this.ProductName=ProductName; this.Price=Price } static async findAll(ProductID) { const Pull_Products=await SingletonSqlHandler.instance.sendQuery('SELECT * from dbo.getAllProducts()') return Pull_Products; } } module.exports = Product productRoute.js: const router = require('express').Router(); const productController=require('../Controllers/productController') router.get('/takeData', productController.takeData); module.exports = router; This is an example of pull the data from the net: https://medium.com/tech-tajawal/introduction-to-caching-redis-node-js-e477eb969eab This article is a very simple introduction to Redis and how caching works, by

14th May 2020, 7:27 AM
Hiba Yousef
Hiba Yousef - avatar
1 ответ
0
You got to Install and start Redis server
16th May 2020, 5:15 AM
Calviղ
Calviղ - avatar