Performance tuning done

This commit is contained in:
2026-07-23 11:53:40 +05:30
parent 4cbd510b85
commit dcb40473da
2155 changed files with 652296 additions and 230 deletions

View File

@@ -0,0 +1,44 @@
package com.cygnus.cloud.cache;
import java.time.Duration;
import org.springframework.data.redis.core.ReactiveStringRedisTemplate;
import org.springframework.stereotype.Service;
import reactor.core.publisher.Mono;
@Service
public class ReactiveCacheService {
private final ReactiveStringRedisTemplate redis;
private final CacheProperties properties;
public ReactiveCacheService(ReactiveStringRedisTemplate redis, CacheProperties properties) {
this.redis = redis;
this.properties = properties;
}
public Mono<String> get(String namespace, String key) {
return redis.opsForValue().get(cacheKey(namespace, key));
}
public Mono<Boolean> put(String namespace, String key, String value) {
return put(namespace, key, value, properties.defaultTtl());
}
public Mono<Boolean> put(String namespace, String key, String value, Duration ttl) {
return redis.opsForValue().set(cacheKey(namespace, key), value, ttl);
}
public Mono<Boolean> putIfAbsent(String namespace, String key, String value, Duration ttl) {
return redis.opsForValue().setIfAbsent(cacheKey(namespace, key), value, ttl);
}
public Mono<Boolean> evict(String namespace, String key) {
return redis.delete(cacheKey(namespace, key)).map(deleted -> deleted > 0);
}
private String cacheKey(String namespace, String key) {
return properties.keyPrefix() + ':' + namespace + ':' + key;
}
}