This repository contains a Spring Boot application that demonstrates the integration of caching mechanisms to enhance API performance. The primary goal is to compare the performance results between API endpoints with caching enabled and those without caching.
- Spring Boot framework
- Spring Data JPA for database operations
- H2 in-memory database for development and testing
- Caching using Spring Cache abstraction
- Performance comparison of API endpoints with and without caching
- Java 11 or higher
- Maven 3.6.0 or higher
- Docker and Docker Compose
-
Clone the repository:
git clone https://github.com/youssefGamalMohamed/spring-boot-caching.git cd spring-boot-caching
-
Configure the database and server: The application is preconfigured to use an H2 in-memory database. You can find the configuration in the
application.yaml
file:server: port: 9091 servlet: context-path: /social/api/v1 spring: datasource: url: jdbc:h2:mem:socialDb driverClassName: org.h2.Driver username: admin password: admin h2: console: enabled: true jpa: hibernate: ddl-auto: update show-sql: true database-platform: org.hibernate.dialect.H2Dialect cache: type: simple
-
Build the project:
mvn clean install
-
Run the application:
mvn spring-boot:run
-
Ensure Docker and Docker Compose are installed:
- Docker: Installation Guide
- Docker Compose: Installation Guide
-
Build and start the containers:
docker-compose up --build
This command will start the Spring Boot application and Redis service in containers.
-
Access the application:
- The application will be accessible at:
http://localhost:9091/social/api/v1
- The application will be accessible at:
- Create a post:
POST /social/api/v1/posts
- Retrieve a post by ID:
GET /social/api/v1/posts/{id}
- Delete a post by ID:
DELETE /social/api/v1/posts/{id}
- H2 Console: http://localhost:9091/h2-console
- JDBC URL:
jdbc:h2:mem:socialDb
- Username:
admin
- Password:
admin
- JDBC URL:
- Fork the repository
- Create a new branch (
git checkout -b feature-branch
) - Commit your changes (
git commit -m 'Add new feature'
) - Push to the branch (
git push origin feature-branch
) - Create a new Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
For any questions or suggestions, feel free to open an issue or contact the repository owner.