Posts

Showing posts with the label read-through

READ-THROUGH

Image
Introduction This article will guide you on implementing READ-THROUGH in NestJS with Redis and Postgres I will also use @nestjs/cache-manager to create an Abstraction layer That is a Cache Interceptor acting as the single source of truth where the app only needs to retrieve data from it. If the cache is unavailable, it will query the Database to fetch data and save it into the cache Regarding the theoretical content, you can review the previous article where I covered it Detail Please install the following packages bun add cache-manager cache-manager-redis-yet @nestjs/cache-manager Create file module/cache-manager.module.ts to create CacheManagerModule connecting to Redis . The app will view this as the data source and only fetch data from here import { CacheModule } from '@nestjs/cache-manager' import { Module } from '@nestjs/common' import { ConfigModule , ConfigService } from '@nestjs/config' import {redisStore} from 'cach...

Implement Caching Strategies with React Query

Image
Introduction You can view the theoretical content about Caching strategies presented here These Caching Patterns are not only used on the Backend but can also be implemented on the Frontend You only need to replace the role of Redis typically used with Memory (or use Local Storage, IndexedDB on the Browser ), while replacing the query fetching data from the Database with response data from the Server API In this article, I will guide you on using React Query combined with IndexedDB (using @tanstack/react-query-persist-client and idb-keyval ) to implement Caching strategies in a simple and effective way Cache patterns CACHE-ASIDE (Lazy Loading) & READ-THROUGH This is the default mechanism of useQuery . Cache-Aside : Check the cache first, if it does not exist, fetch from the API and save to the cache. Read-Through : The client interacts through an abstraction layer (hook) and the hook automatically decides whether to retrieve data from the cache or the server. REFRESH-AHEA...