Posts

Showing posts with the label strategy

Design Patterns

Image
Introduction Gang of Four (GoF) is a term referring to a group of 4 authors ( Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides ) who published the classic book Design Patterns: Elements of Reusable Object-Oriented Software in 1994 . The book summarizes 23 design patterns commonly used to solve recurring object-oriented programming ( OOP ) design problems. The main benefit of GoF Design Patterns is providing standardized solutions to common problems, making source code easier to maintain, extend and creating a common language for developers when discussing software architecture. These 23 design patterns are divided into 3 main groups: Creational Patterns Factory Method : Defines an interface for creating an object, but lets subclasses decide which class to instantiate. Abstract Factory : Provides an interface for creating families of related or dependent objects without specifying their concrete classes. Builder : Separates the construction of a complex obj...

REFRESH-AHEAD

Image
Introduction This article will guide you on how to implement REFRESH-AHEAD on NestJS with Redis and Postgres . We will need to use @nestjs/cache-manager to create a service that handles keys about to expire. We will also use @nestjs/bullmq for background processing to query the database and update the cache. For theoretical details, you can review the previous article where I covered this topic. Detail Create the file constant/index.ts with Queue, Job and Function as follows: export enum QueueName { CACHE_REFRESH = 'cache-refresh' , } export enum JobName { REFRESH_KEY = 'refresh-key' , } export enum FunctionName { PRODUCT_DETAIL = 'product-detail' , TRENDING_PRODUCT = 'trending-product' , } Create file module/bullmq.module.ts import { BullModule } from '@nestjs/bullmq' import { Module } from '@nestjs/common' import { ConfigModule , ConfigService } from '@nestjs/config' import { QueueName } f...