RedisLocalCacheStore implements CacheStore { @Override public boolean delete(String... keys) { boolean deleted = redisCache.delete(keys); localCache.delete(keys); if (deleted) { publishInvalidateLocalCacheMessage(Arrays.asList(keys)); } return deleted; } 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 deleteWithRemoteExpired() { when(redisCacheStore.delete("key1")).thenReturn(Boolean.FALSE); cacheStore.delete("key1"); verify(localCacheStore).delete("key1"); verify(redis, never()).publish(eq(CHANNEL_INVALIDATE_CACHE), any()); }
@Test void delete() { when(redisCacheStore.delete("key1")).thenReturn(Boolean.TRUE); cacheStore.delete("key1"); verify(localCacheStore).delete("key1"); verify(redis).publish(eq(CHANNEL_INVALIDATE_CACHE), any()); }