How vanh01/caching-strategies works
Main Components of the System
a. Entry Point & Application Bootstrap:
• The cmd directory (specifically cmd/main.go) represents the application’s starting point.
• Dockerfile and docker-compose.yml indicate containerized deployment.
b. Configuration & Initialization:
• config.yaml and the files inside the config folder (e.g., config/config.go) are used to configure the system.
• init.sql suggests there is a SQL component for database initialization.
c. Core Layers (Following a Layered Architecture):
• internal/app: Contains the main application logic (internal/app/app.go) for bootstrapping.
• internal/controller: The routing and API request handling layer (internal/controller/router.go).
• internal/usecase: Contains business logic (internal/usecase/user.go and interfaces.go) which likely coordinates between controllers and repositories.
• internal/repo: Handles data persistence and retrieval, probably interacting with the database (internal/repo/user.go, constant.go).
• internal/model: Holds data models (internal/model/user.go) used across the system.
d. Caching Strategies:
• internal/cus_cache: Implements at least one caching strategy (see read_through.go).
• pkg/cache: Provides caching functionalities using Redis (pkg/cache/redis.go) which acts as a common cache module.
• The test and report folders include scripts and outputs associated with different caching strategies (original, cache-aside, and read-through).
e. Testing & Reporting:
• The test directory contains JavaScript files to perform load tests for the caching strategies.
• The report folder saves output logs or performance assessments for each strategy.
Relationships & Data Flow
• The entry point (cmd/main.go) “boots” the app by loading the configuration (from config.yaml via config/ folder) and initializing the application layer.
• Requests are routed by the controller (internal/controller/router.go) which triggers business logic in the usecase layer.
• The usecase layer interacts with the repository to fetch or update data from the underlying database (set up by init.sql) as well as with the caching implementations.
• Caching is handled in two flavors:
• Custom caching strategies (internal/cus_cache) that likely demonstrate specific caching techniques.
• A Redis cache implementation in pkg/cache as a utility.
• Testing scripts simulate client requests against these strategies, and results are written into the report folder, exhibiting performance differences.
Architectural Patterns & Design Principles
• Layered Architecture: Clear separation between presentation (controller), business logic (usecase), and data persistence (repo).
• Modular Design: Different caching strategies are isolated in their respective directories (both custom implementations and external integrations like Redis).
• Containerized Deployment: Use of Docker and related configuration files for running the application in isolated environments.
• Separation of concerns: Configurations, business logic, data models, and caching strategies are each in their own directories.
A Detailed and Granular Approach
• Every folder or file grouping that provides unique functionality is represented.
• Dependencies (e.g., the relationship between the business logic and both caching implementations).