RedisLocalCacheStore implements CacheStore { @Override public <T> T get(String key, CacheContext<T> context) { T value = localCache.get(key, context); if (value != null) return value; value = redisCache.get(key, context); if (value == null) return null; long expirationTime = redis.expirationTime(key)[0]; if (expirationTime <= 0) return null; localCache.put(key, value, Duration.ofMillis(expirationTime), context); return value; } RedisLocalCacheStore(CacheStore localCache, CacheStore redisCache, RedisImpl redis); @Override T get(String key, CacheContext<T> context); @Override Map<String, T> getAll(String[] keys, CacheContext<T> context); @Override void put(String key, T value, Duration expiration, CacheContext<T> context); @Override void putAll(List<Entry<T>> values, Duration expiration, CacheContext<T> context); @Override boolean delete(String... keys); static final String CHANNEL_INVALIDATE_CACHE; }
@Test void getWithLocalHit() { var value = new TestCache(); when(localCacheStore.get("key", null)).thenReturn(value); assertThat(cacheStore.<TestCache>get("key", null)).isSameAs(value); }
@Test void getWithMiss() { when(localCacheStore.get("key", null)).thenReturn(null); when(redisCacheStore.get("key", null)).thenReturn(null); assertThat(cacheStore.<TestCache>get("key", null)).isNull(); }