Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cache/cache-annotation-processor/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ dependencies {
testImplementation testFixtures(project(":annotation-processor-common"))
testImplementation project(":internal:test-logging")
testImplementation project(":cache:cache-caffeine")
testImplementation project(":cache:cache-redis")
testImplementation project(":cache:cache-redis-lettuce")
testImplementation project(":json:json-common")
testImplementation project(":config:config-common")
}
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ private CacheableAsync getService() {
final Constructor<?> cacheConstructor = cacheClass.getDeclaredConstructors()[0];
cacheConstructor.setAccessible(true);
cache = (DummyCache21) cacheConstructor.newInstance(CacheRunner.getCaffeineConfig(),
caffeineCacheFactory(null), caffeineCacheTelemetry(null, null));
caffeineCacheFactory(null), defaultCacheTelemetryFactory(null, null, null));

var serviceClass = classLoader.loadClass(CACHED_SERVICE);
if (serviceClass == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import ru.tinkoff.kora.cache.annotation.processor.testdata.async.CacheableAsyncMany;
import ru.tinkoff.kora.cache.caffeine.CaffeineCacheModule;
import ru.tinkoff.kora.cache.redis.RedisCacheKeyMapper;
import ru.tinkoff.kora.cache.redis.RedisCacheMapperModule;
import ru.tinkoff.kora.cache.redis.RedisCacheModule;

import java.lang.reflect.Constructor;
Expand Down Expand Up @@ -51,7 +50,7 @@ private CacheableAsyncMany getService() {
final Constructor<?> cacheConstructor1 = cacheClass1.getDeclaredConstructors()[0];
cacheConstructor1.setAccessible(true);
cache1 = (DummyCache21) cacheConstructor1.newInstance(CacheRunner.getCaffeineConfig(),
caffeineCacheFactory(null), caffeineCacheTelemetry(null, null));
caffeineCacheFactory(null), defaultCacheTelemetryFactory(null, null, null));

var cacheClass2 = classLoader.loadClass(CACHED_IMPL_2);
if (cacheClass2 == null) {
Expand All @@ -62,7 +61,7 @@ private CacheableAsyncMany getService() {
cacheConstructor2.setAccessible(true);
final Map<ByteBuffer, ByteBuffer> cache = new HashMap<>();
cache2 = (DummyCache22) cacheConstructor2.newInstance(CacheRunner.getRedisConfig(),
CacheRunner.lettuceClient(cache), redisCacheTelemetry(null, null),
CacheRunner.lettuceSyncClient(cache), CacheRunner.lettuceAsyncClient(cache), defaultCacheTelemetryFactory(null, null, null),
(RedisCacheKeyMapper<DummyCache22.Key>) key -> {
var _key1 = key.k1().getBytes(StandardCharsets.UTF_8);
var _key2 = key.k2().toString().getBytes(StandardCharsets.UTF_8);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import ru.tinkoff.kora.aop.annotation.processor.AopAnnotationProcessor;
import ru.tinkoff.kora.cache.annotation.processor.testcache.DummyCache21;
import ru.tinkoff.kora.cache.annotation.processor.testcache.DummyCache22;
import ru.tinkoff.kora.cache.annotation.processor.testdata.async.CacheableAsyncMany;
import ru.tinkoff.kora.cache.annotation.processor.testdata.async.CacheableAsyncManyOptional;
import ru.tinkoff.kora.cache.caffeine.CaffeineCacheModule;
import ru.tinkoff.kora.cache.redis.RedisCacheKeyMapper;
Expand Down Expand Up @@ -51,7 +50,7 @@ private CacheableAsyncManyOptional getService() {
final Constructor<?> cacheConstructor1 = cacheClass1.getDeclaredConstructors()[0];
cacheConstructor1.setAccessible(true);
cache1 = (DummyCache21) cacheConstructor1.newInstance(CacheRunner.getCaffeineConfig(),
caffeineCacheFactory(null), caffeineCacheTelemetry(null, null));
caffeineCacheFactory(null), defaultCacheTelemetryFactory(null, null, null));

var cacheClass2 = classLoader.loadClass(CACHED_IMPL_2);
if (cacheClass2 == null) {
Expand All @@ -62,7 +61,7 @@ private CacheableAsyncManyOptional getService() {
cacheConstructor2.setAccessible(true);
final Map<ByteBuffer, ByteBuffer> cache = new HashMap<>();
cache2 = (DummyCache22) cacheConstructor2.newInstance(CacheRunner.getRedisConfig(),
CacheRunner.lettuceClient(cache), redisCacheTelemetry(null, null),
CacheRunner.lettuceSyncClient(cache), CacheRunner.lettuceAsyncClient(cache), defaultCacheTelemetryFactory(null, null, null),
(RedisCacheKeyMapper<DummyCache22.Key>) key -> {
var _key1 = key.k1().getBytes(StandardCharsets.UTF_8);
var _key2 = key.k2().toString().getBytes(StandardCharsets.UTF_8);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ private CacheableAsyncOne getService() {
final Constructor<?> cacheConstructor = cacheClass.getDeclaredConstructors()[0];
cacheConstructor.setAccessible(true);
cache = (DummyCache11) cacheConstructor.newInstance(CacheRunner.getCaffeineConfig(),
caffeineCacheFactory(null), caffeineCacheTelemetry(null, null));
caffeineCacheFactory(null), defaultCacheTelemetryFactory(null, null, null));

var serviceClass = classLoader.loadClass(CACHED_SERVICE);
if (serviceClass == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import ru.tinkoff.kora.cache.annotation.processor.testcache.DummyCache12;
import ru.tinkoff.kora.cache.annotation.processor.testdata.async.CacheableAsyncOneMany;
import ru.tinkoff.kora.cache.caffeine.CaffeineCacheModule;
import ru.tinkoff.kora.cache.redis.RedisCacheMapperModule;
import ru.tinkoff.kora.cache.redis.RedisCacheModule;

import java.lang.reflect.Constructor;
Expand Down Expand Up @@ -49,7 +48,7 @@ private CacheableAsyncOneMany getService() {
final Constructor<?> cacheConstructor1 = cacheClass1.getDeclaredConstructors()[0];
cacheConstructor1.setAccessible(true);
cache1 = (DummyCache11) cacheConstructor1.newInstance(CacheRunner.getCaffeineConfig(),
caffeineCacheFactory(null), caffeineCacheTelemetry(null, null));
caffeineCacheFactory(null), defaultCacheTelemetryFactory(null, null, null));

var cacheClass2 = classLoader.loadClass(CACHED_IMPL_2);
if (cacheClass2 == null) {
Expand All @@ -60,7 +59,7 @@ private CacheableAsyncOneMany getService() {
cacheConstructor2.setAccessible(true);
final Map<ByteBuffer, ByteBuffer> cache = new HashMap<>();
cache2 = (DummyCache12) cacheConstructor2.newInstance(CacheRunner.getRedisConfig(),
CacheRunner.lettuceClient(cache), redisCacheTelemetry(null, null),
CacheRunner.lettuceSyncClient(cache), CacheRunner.lettuceAsyncClient(cache), defaultCacheTelemetryFactory(null, null, null),
stringRedisKeyMapper(), stringRedisValueMapper());

var serviceClass = classLoader.loadClass(CACHED_SERVICE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ private CacheableAsyncOneManySync getService() {
final Constructor<?> cacheConstructor1 = cacheClass1.getDeclaredConstructors()[0];
cacheConstructor1.setAccessible(true);
cache1 = (DummyCache11) cacheConstructor1.newInstance(CacheRunner.getCaffeineConfig(),
caffeineCacheFactory(null), caffeineCacheTelemetry(null, null));
caffeineCacheFactory(null), defaultCacheTelemetryFactory(null, null, null));

var cacheClass2 = classLoader.loadClass(CACHED_IMPL_2);
if (cacheClass2 == null) {
Expand All @@ -60,7 +60,7 @@ private CacheableAsyncOneManySync getService() {
final Constructor<?> cacheConstructor2 = cacheClass2.getDeclaredConstructors()[0];
cacheConstructor2.setAccessible(true);
cache2 = (DummyCache13) cacheConstructor2.newInstance(CacheRunner.getCaffeineConfig(),
caffeineCacheFactory(null), caffeineCacheTelemetry(null, null));
caffeineCacheFactory(null), defaultCacheTelemetryFactory(null, null, null));

var serviceClass = classLoader.loadClass(CACHED_SERVICE);
if (serviceClass == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ private CacheableAsyncOptional getService() {
final Constructor<?> cacheConstructor = cacheClass.getDeclaredConstructors()[0];
cacheConstructor.setAccessible(true);
cache = (DummyCache21) cacheConstructor.newInstance(CacheRunner.getCaffeineConfig(),
caffeineCacheFactory(null), caffeineCacheTelemetry(null, null));
caffeineCacheFactory(null), defaultCacheTelemetryFactory(null, null, null));

var serviceClass = classLoader.loadClass(CACHED_SERVICE);
if (serviceClass == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public void evictValue(String arg1) {
compileResult.assertSuccess();

var cache = newObject("$DummyCacheImpl", CacheRunner.getCaffeineConfig(),
caffeineCacheFactory(null), caffeineCacheTelemetry(null, null));
caffeineCacheFactory(null), defaultCacheTelemetryFactory(null, null, null));
assertThat(cache).isNotNull();

var service = newObject("$CacheableSync__AopProxy", cache);
Expand Down Expand Up @@ -83,10 +83,10 @@ public void evictValue(String arg1) {
compileResult.assertSuccess();

var cache1 = newObject("$DummyCache1Impl", CacheRunner.getCaffeineConfig(),
caffeineCacheFactory(null), caffeineCacheTelemetry(null, null));
caffeineCacheFactory(null), defaultCacheTelemetryFactory(null, null, null));
assertThat(cache1).isNotNull();
var cache2 = newObject("$DummyCache2Impl", CacheRunner.getCaffeineConfig(),
caffeineCacheFactory(null), caffeineCacheTelemetry(null, null));
caffeineCacheFactory(null), defaultCacheTelemetryFactory(null, null, null));
assertThat(cache2).isNotNull();

var service = newObject("$CacheableSync__AopProxy", cache1, cache2);
Expand Down Expand Up @@ -123,7 +123,7 @@ public void evictValue(String arg1) {
compileResult.assertSuccess();

var cache = newObject("$DummyCacheImpl", CacheRunner.getCaffeineConfig(),
caffeineCacheFactory(null), caffeineCacheTelemetry(null, null));
caffeineCacheFactory(null), defaultCacheTelemetryFactory(null, null, null));
assertThat(cache).isNotNull();

var service = newObject("$CacheableSync__AopProxy", cache);
Expand Down Expand Up @@ -166,10 +166,10 @@ public void evictValue(String arg1) {
compileResult.assertSuccess();

var cache1 = newObject("$DummyCache1Impl", CacheRunner.getCaffeineConfig(),
caffeineCacheFactory(null), caffeineCacheTelemetry(null, null));
caffeineCacheFactory(null), defaultCacheTelemetryFactory(null, null, null));
assertThat(cache1).isNotNull();
var cache2 = newObject("$DummyCache2Impl", CacheRunner.getCaffeineConfig(),
caffeineCacheFactory(null), caffeineCacheTelemetry(null, null));
caffeineCacheFactory(null), defaultCacheTelemetryFactory(null, null, null));
assertThat(cache2).isNotNull();

var service = newObject("$CacheableSync__AopProxy", cache1, cache2);
Expand Down Expand Up @@ -206,7 +206,7 @@ public void evictValue(String arg1) {
compileResult.assertSuccess();

var cache = newObject("$DummyCacheImpl", CacheRunner.getCaffeineConfig(),
caffeineCacheFactory(null), caffeineCacheTelemetry(null, null));
caffeineCacheFactory(null), defaultCacheTelemetryFactory(null, null, null));
assertThat(cache).isNotNull();

var service = newObject("$CacheableSync__AopProxy", cache);
Expand Down Expand Up @@ -249,10 +249,10 @@ public void evictValue(String arg1) {
compileResult.assertSuccess();

var cache1 = newObject("$DummyCache1Impl", CacheRunner.getCaffeineConfig(),
caffeineCacheFactory(null), caffeineCacheTelemetry(null, null));
caffeineCacheFactory(null), defaultCacheTelemetryFactory(null, null, null));
assertThat(cache1).isNotNull();
var cache2 = newObject("$DummyCache2Impl", CacheRunner.getCaffeineConfig(),
caffeineCacheFactory(null), caffeineCacheTelemetry(null, null));
caffeineCacheFactory(null), defaultCacheTelemetryFactory(null, null, null));
assertThat(cache2).isNotNull();

var service = newObject("$CacheableSync__AopProxy", cache1, cache2);
Expand Down Expand Up @@ -295,10 +295,10 @@ public void evictValue(String arg1) {
compileResult.assertSuccess();

var cache1 = newObject("$DummyCache1Impl", CacheRunner.getCaffeineConfig(),
caffeineCacheFactory(null), caffeineCacheTelemetry(null, null));
caffeineCacheFactory(null), defaultCacheTelemetryFactory(null, null, null));
assertThat(cache1).isNotNull();
var cache2 = newObject("$DummyCache2Impl", CacheRunner.getCaffeineConfig(),
caffeineCacheFactory(null), caffeineCacheTelemetry(null, null));
caffeineCacheFactory(null), defaultCacheTelemetryFactory(null, null, null));
assertThat(cache2).isNotNull();

var service = newObject("$CacheableSync__AopProxy", cache1, cache2);
Expand Down Expand Up @@ -341,10 +341,10 @@ public void evictValue(String arg1) {
compileResult.assertSuccess();

var cache1 = newObject("$DummyCache1Impl", CacheRunner.getCaffeineConfig(),
caffeineCacheFactory(null), caffeineCacheTelemetry(null, null));
caffeineCacheFactory(null), defaultCacheTelemetryFactory(null, null, null));
assertThat(cache1).isNotNull();
var cache2 = newObject("$DummyCache2Impl", CacheRunner.getCaffeineConfig(),
caffeineCacheFactory(null), caffeineCacheTelemetry(null, null));
caffeineCacheFactory(null), defaultCacheTelemetryFactory(null, null, null));
assertThat(cache2).isNotNull();

var service = newObject("$CacheableSync__AopProxy", cache1, cache2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
import jakarta.annotation.Nonnull;
import jakarta.annotation.Nullable;
import ru.tinkoff.kora.cache.caffeine.CaffeineCacheConfig;
import ru.tinkoff.kora.cache.redis.RedisCacheAsyncClient;
import ru.tinkoff.kora.cache.redis.RedisCacheClient;
import ru.tinkoff.kora.cache.redis.RedisCacheConfig;
import ru.tinkoff.kora.telemetry.common.TelemetryConfig;

import java.nio.ByteBuffer;
import java.time.Duration;
Expand Down Expand Up @@ -37,6 +39,11 @@ public Duration expireAfterAccess() {
public Integer initialSize() {
return null;
}

@Override
public TelemetryConfig telemetry() {
return null;
}
};
}

Expand All @@ -59,11 +66,16 @@ public Duration expireAfterWrite() {
public Duration expireAfterAccess() {
return null;
}

@Override
public TelemetryConfig telemetry() {
return null;
}
};
}

public static RedisCacheClient lettuceClient(final Map<ByteBuffer, ByteBuffer> cache) {
return new RedisCacheClient() {
public static RedisCacheAsyncClient lettuceAsyncClient(final Map<ByteBuffer, ByteBuffer> cache) {
return new RedisCacheAsyncClient() {
@Override
public CompletionStage<byte[]> get(byte[] key) {
var r = cache.get(ByteBuffer.wrap(key));
Expand Down Expand Up @@ -94,24 +106,24 @@ public CompletionStage<Map<byte[], byte[]>> getex(byte[][] keys, long expireAfte
}

@Override
public CompletionStage<Boolean> set(byte[] key, byte[] value) {
public CompletionStage<Void> set(byte[] key, byte[] value) {
cache.put(ByteBuffer.wrap(key), ByteBuffer.wrap(value));
return CompletableFuture.completedFuture(true);
return CompletableFuture.completedFuture(null);
}

@Override
public CompletionStage<Boolean> mset(Map<byte[], byte[]> keyAndValue) {
public CompletionStage<Void> mset(Map<byte[], byte[]> keyAndValue) {
keyAndValue.forEach((k, v) -> cache.put(ByteBuffer.wrap(k), ByteBuffer.wrap(v)));
return CompletableFuture.completedFuture(true);
return CompletableFuture.completedFuture(null);
}

@Override
public CompletionStage<Boolean> psetex(Map<byte[], byte[]> keyAndValue, long expireAfterMillis) {
public CompletionStage<Void> psetex(Map<byte[], byte[]> keyAndValue, long expireAfterMillis) {
return mset(keyAndValue);
}

@Override
public CompletionStage<Boolean> psetex(byte[] key, byte[] value, long expireAfterMillis) {
public CompletionStage<Void> psetex(byte[] key, byte[] value, long expireAfterMillis) {
return set(key, value);
}

Expand All @@ -130,9 +142,81 @@ public CompletionStage<Long> del(byte[][] keys) {
}

@Override
public CompletionStage<Boolean> flushAll() {
public CompletionStage<Void> flushAll() {
cache.clear();
return CompletableFuture.completedFuture(null);
}
};
}

public static RedisCacheClient lettuceSyncClient(final Map<ByteBuffer, ByteBuffer> cache) {
return new RedisCacheClient() {
@Override
public byte[] get(byte[] key) {
var r = cache.get(ByteBuffer.wrap(key));
return (r == null)
? null
: r.array();
}

@Nonnull
@Override
public Map<byte[], byte[]> mget(byte[][] keys) {
final Map<byte[], byte[]> result = new HashMap<>();
for (byte[] key : keys) {
Optional.ofNullable(cache.get(ByteBuffer.wrap(key))).ifPresent(r -> result.put(key, r.array()));
}
return result;
}

@Override
public byte[] getex(byte[] key, long expireAfterMillis) {
return get(key);
}

@Nonnull
@Override
public Map<byte[], byte[]> getex(byte[][] keys, long expireAfterMillis) {
return mget(keys);
}

@Override
public void set(byte[] key, byte[] value) {
cache.put(ByteBuffer.wrap(key), ByteBuffer.wrap(value));
}

@Override
public void mset(Map<byte[], byte[]> keyAndValue) {
keyAndValue.forEach((k, v) -> cache.put(ByteBuffer.wrap(k), ByteBuffer.wrap(v)));
}

@Override
public void psetex(Map<byte[], byte[]> keyAndValue, long expireAfterMillis) {
mset(keyAndValue);
}

@Override
public void psetex(byte[] key, byte[] value, long expireAfterMillis) {
set(key, value);
}

@Override
public long del(byte[] key) {
return cache.remove(ByteBuffer.wrap(key)) == null ? 0L : 1L;
}

@Override
public long del(byte[][] keys) {
long counter = 0;
for (byte[] key : keys) {
counter += del(key);
}
return counter;
}

@Override
public void flushAll() {
cache.clear();
return CompletableFuture.completedFuture(true);
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ private CacheableMono getService() {
cacheConstructor.setAccessible(true);
final Map<ByteBuffer, ByteBuffer> cacheBuf = new HashMap<>();
cache = (DummyCache22) cacheConstructor.newInstance(CacheRunner.getRedisConfig(),
CacheRunner.lettuceClient(cacheBuf), redisCacheTelemetry(null, null),
CacheRunner.lettuceSyncClient(cacheBuf), CacheRunner.lettuceAsyncClient(cacheBuf), defaultCacheTelemetryFactory(null, null, null),
(RedisCacheKeyMapper<DummyCache22.Key>) key -> {
var _key1 = key.k1().getBytes(StandardCharsets.UTF_8);
var _key2 = key.k2().toString().getBytes(StandardCharsets.UTF_8);
Expand Down
Loading