20 Mart 2023 Pazartesi

Cache Stratejileri - Cache Access Patterns Write-Through - Implemented by Cache Provider

Açıklaması şöyle. Yani önce cache güncellenir, sonra veri tabanı güncellenir,
1. The application writes the data directly to the cache.
2. The cache updates the data in the main database. When the write is complete, both the cache and the database have the same value and the cache always remains consistent.
MapWriter kullanılır. Açıklaması şöyle
whenever any “write” request comes, it will come through the cache to the DB. Write is considered successful only if data is written successfully in the cache and in DB.
Eğer Spring ile bunu taklit etmek istersek şöyle yaparız
// With Spring you can mimic it
// Both DB + cache updated synchronously.
@CachePut(value = "users", key = "#user.id")
public User saveUser(User user) {
    return userRepository.save(user);
}


Hiç yorum yok:

Yorum Gönder