Hackforge Academy

Category: java

what is redis

Published on 16 Jul 2026

Explanation

Redis is an in-memory data store used for caching frequently accessed data. Caching reduces database queries and significantly improves REST API performance.

Code:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>

Explanation

Enable caching in the Spring Boot application by using the @EnableCaching annotation. This activates Spring's cache abstraction.

Code:

@SpringBootApplication
@EnableCaching
public class Application {
}

Explanation

Use the @Cacheable annotation to cache the results of frequently executed methods. If the data is already in Redis, the database is not queried again.

Code:

@Cacheable("students")
public List<Student> getStudents() {
    return repository.findAll();
}

Explanation

Use the @CachePut annotation to update the cache whenever a record is modified. This keeps cached data synchronized with the database.

Code:

@CachePut(value = "students", key = "#student.id")
public Student updateStudent(Student student) {
    return repository.save(student);
}

Explanation

Use the @CacheEvict annotation to remove outdated cache entries after deleting or updating records. This prevents stale data from being returned.

Code:

@CacheEvict(value = "students", allEntries = true)
public void deleteStudent(Long id) {
    repository.deleteById(id);
}

๐Ÿš€ Learn Spring Boot with real-world projects

๐Ÿ’ก Build REST APIs step by step

๐Ÿง  Improve backend development skills

๐ŸŽฏ Get career-ready practical training

Join Our Free WhatsApp Community

Direct access to niche-specific mentors and peers on WhatsApp.

๐Ÿ

Python Community

Discuss Django, FastAPI, AI integration, and automation scripts with 15k+ developers.

Join Python Community
โš›๏ธ

React Community

Master Next.js, Framer Motion, and State Management. Share your latest UI components.

Join React Community
โ˜•

Java Community

Deep dives into Spring Boot, Microservices architecture, and high-performance backend ops.

Join Java Community