diff --git a/src/main/java/com/chint/infrastructure/repository/PermissionConfigRepositoryImpl.java b/src/main/java/com/chint/infrastructure/repository/PermissionConfigRepositoryImpl.java index 36e36328..34f5420a 100644 --- a/src/main/java/com/chint/infrastructure/repository/PermissionConfigRepositoryImpl.java +++ b/src/main/java/com/chint/infrastructure/repository/PermissionConfigRepositoryImpl.java @@ -5,7 +5,6 @@ import com.chint.domain.repository.PermissionConfigRepository; import com.chint.infrastructure.repository.cache.CachePermissionConfigRepository; import com.chint.infrastructure.repository.jdbc.JdbcPermissionConfigRepository; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.cache.annotation.Cacheable; import org.springframework.stereotype.Repository; import java.util.*; @@ -20,12 +19,18 @@ public class PermissionConfigRepositoryImpl implements PermissionConfigRepositor @Autowired private CachePermissionConfigRepository cachePermissionConfigRepository; - @Cacheable(value = "PermissionConfig", key = "#permissionName") + @Override public Optional findByPermissionName(String permissionName) { - return jdbcPermissionConfigRepository.findByPermissionName(permissionName) - .stream() - .findFirst(); + PermissionConfig permissionConfig = cachePermissionConfigRepository.cacheByName(permissionName, null); + if (permissionConfig == null) { + Optional first = jdbcPermissionConfigRepository.findByPermissionName(permissionName) + .stream() + .findFirst(); + first.ifPresent(it -> cachePermissionConfigRepository.cacheByName(it)); + return first; + } + return Optional.of(permissionConfig); } @Override diff --git a/src/main/java/com/chint/infrastructure/repository/cache/CachePermissionConfigRepository.java b/src/main/java/com/chint/infrastructure/repository/cache/CachePermissionConfigRepository.java index 03d15bff..5f78c12c 100644 --- a/src/main/java/com/chint/infrastructure/repository/cache/CachePermissionConfigRepository.java +++ b/src/main/java/com/chint/infrastructure/repository/cache/CachePermissionConfigRepository.java @@ -40,6 +40,11 @@ public class CachePermissionConfigRepository { return permissionConfig; } + @Cacheable(value = "PermissionConfig", key = "#permissionConfigName") + public PermissionConfig cacheByName(String permissionConfigName, PermissionConfig permissionConfig) { + return permissionConfig; + } + @Cacheable(value = "PermissionConfig", key = "#permissionName") public void cacheEvictByName(String permissionName) { }