Skip to content

Commit b52edf6

Browse files
Align naming of RedisCache and RedisCacheWriter
1 parent fdb30a5 commit b52edf6

File tree

4 files changed

+35
-18
lines changed

4 files changed

+35
-18
lines changed

src/main/java/org/springframework/data/redis/cache/DefaultRedisCacheWriter.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -416,20 +416,20 @@ public byte[] putIfAbsent(String name, byte[] key, byte[] value, @Nullable Durat
416416
}
417417

418418
@Override
419-
public void remove(String name, byte[] key) {
419+
public void evict(String name, byte[] key) {
420420

421421
Assert.notNull(name, "Name must not be null");
422422
Assert.notNull(key, "Key must not be null");
423423

424424
if (writeAsynchronously()) {
425425
asyncCacheWriter.remove(name, key).thenRun(() -> statistics.incDeletes(name));
426426
} else {
427-
removeIfPresent(name, key);
427+
evictIfPresent(name, key);
428428
}
429429
}
430430

431431
@Override
432-
public boolean removeIfPresent(String name, byte[] key) {
432+
public boolean evictIfPresent(String name, byte[] key) {
433433

434434
Long removals = execute(name, connection -> connection.keyCommands().del(key));
435435
statistics.incDeletes(name);

src/main/java/org/springframework/data/redis/cache/RedisCache.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,12 +265,12 @@ public void clearStatistics() {
265265

266266
@Override
267267
public void evict(Object key) {
268-
getCacheWriter().remove(getName(), createAndConvertCacheKey(key));
268+
getCacheWriter().evict(getName(), createAndConvertCacheKey(key));
269269
}
270270

271271
@Override
272272
public boolean evictIfPresent(Object key) {
273-
return getCacheWriter().removeIfPresent(getName(), createAndConvertCacheKey(key));
273+
return getCacheWriter().evictIfPresent(getName(), createAndConvertCacheKey(key));
274274
}
275275

276276
@Override

src/main/java/org/springframework/data/redis/cache/RedisCacheWriter.java

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,24 @@ default CompletableFuture<byte[]> retrieve(String name, byte[] key) {
260260
*
261261
* @param name cache name must not be {@literal null}.
262262
* @param key key for the cache entry. Must not be {@literal null}.
263+
* @deprecated since 4.0 in favor of {@link #evict(String, byte[])}
263264
*/
264-
void remove(String name, byte[] key);
265+
@Deprecated(since = "4.0", forRemoval = true)
266+
default void remove(String name, byte[] key) {
267+
evict(name, key);
268+
}
269+
270+
/**
271+
* Remove the given key from Redis.
272+
* <p>
273+
* Actual eviction may be performed in an asynchronous or deferred fashion, with subsequent lookups possibly still
274+
* seeing the entry.
275+
*
276+
* @param name cache name must not be {@literal null}.
277+
* @param key key for the cache entry. Must not be {@literal null}.
278+
* @since 4.0
279+
*/
280+
void evict(String name, byte[] key);
265281

266282
/**
267283
* Remove the given key from Redis if it is present, expecting the key to be immediately invisible for subsequent
@@ -271,9 +287,10 @@ default CompletableFuture<byte[]> retrieve(String name, byte[] key) {
271287
* @param key key for the cache entry. Must not be {@literal null}.
272288
* @return {@code true} if the cache was known to have a mapping for this key before, {@code false} if it did not (or
273289
* if prior presence could not be determined).
290+
* @since 4.0
274291
*/
275-
default boolean removeIfPresent(String name, byte[] key) {
276-
remove(name, key);
292+
default boolean evictIfPresent(String name, byte[] key) {
293+
evict(name, key);
277294
return false;
278295
}
279296

src/test/java/org/springframework/data/redis/cache/DefaultRedisCacheWriterTests.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -286,27 +286,27 @@ void getWithValueLoaderShouldStoreCacheValue() {
286286
}
287287

288288
@Test // DATAREDIS-481, DATAREDIS-1082
289-
void removeShouldDeleteEntry() {
289+
void evictShouldDeleteEntry() {
290290

291291
doWithConnection(connection -> connection.set(binaryCacheKey, binaryCacheValue));
292292

293293
RedisCacheWriter writer = RedisCacheWriter.create(connectionFactory,
294294
config -> config.collectStatistics().immediateWrites());
295295

296-
writer.remove(CACHE_NAME, binaryCacheKey);
296+
writer.evict(CACHE_NAME, binaryCacheKey);
297297

298298
doWithConnection(connection -> assertThat(connection.exists(binaryCacheKey)).isFalse());
299299

300300
assertThat(writer.getCacheStatistics(CACHE_NAME).getDeletes()).isOne();
301301
}
302302

303303
@Test // GH-3236
304-
void removeShouldNonblockingDeleteEntry() {
304+
void evictShouldNonblockingDeleteEntry() {
305305

306306
RedisCacheWriter writer = RedisCacheWriter.create(connectionFactory, RedisCacheWriterConfigurer::collectStatistics);
307307
assumeTrue(writer.supportsAsyncRetrieve());
308308

309-
writer.remove(CACHE_NAME, binaryCacheKey);
309+
writer.evict(CACHE_NAME, binaryCacheKey);
310310

311311
doWithConnection(connection -> {
312312
Awaitility.await().pollInSameThread().pollDelay(Duration.ZERO).until(() -> !connection.exists(binaryCacheKey));
@@ -317,21 +317,21 @@ void removeShouldNonblockingDeleteEntry() {
317317
}
318318

319319
@Test // GH-3236
320-
void removeShouldDeleteEntryIfExists() {
320+
void evictIfPresentShouldDeleteEntryIfExists() {
321321

322322
doWithConnection(connection -> connection.set(binaryCacheKey, binaryCacheValue));
323323

324324
RedisCacheWriter writer = RedisCacheWriter.create(connectionFactory, RedisCacheWriterConfigurer::collectStatistics);
325325

326-
assertThat(writer.removeIfPresent(CACHE_NAME, binaryCacheKey)).isTrue();
326+
assertThat(writer.evictIfPresent(CACHE_NAME, binaryCacheKey)).isTrue();
327327

328328
doWithConnection(connection -> assertThat(connection.exists(binaryCacheKey)).isFalse());
329329

330330
assertThat(writer.getCacheStatistics(CACHE_NAME).getDeletes()).isOne();
331331
}
332332

333333
@Test // DATAREDIS-418, DATAREDIS-1082
334-
void cleanShouldRemoveAllKeysByPattern() {
334+
void clearShouldRemoveAllKeysByPattern() {
335335

336336
doWithConnection(connection -> {
337337
connection.set(binaryCacheKey, binaryCacheValue);
@@ -341,7 +341,7 @@ void cleanShouldRemoveAllKeysByPattern() {
341341
RedisCacheWriter writer = RedisCacheWriter.create(connectionFactory,
342342
config -> config.collectStatistics().immediateWrites());
343343

344-
writer.clean(CACHE_NAME, (CACHE_NAME + "::*").getBytes(StandardCharsets.UTF_8));
344+
writer.clear(CACHE_NAME, (CACHE_NAME + "::*").getBytes(StandardCharsets.UTF_8));
345345

346346
doWithConnection(connection -> {
347347
assertThat(connection.exists(binaryCacheKey)).isFalse();
@@ -352,7 +352,7 @@ void cleanShouldRemoveAllKeysByPattern() {
352352
}
353353

354354
@Test // GH-3236
355-
void nonBlockingCleanShouldRemoveAllKeysByPattern() {
355+
void nonBlockingClearShouldRemoveAllKeysByPattern() {
356356

357357
RedisCacheWriter writer = RedisCacheWriter.create(connectionFactory, RedisCacheWriterConfigurer::collectStatistics);
358358
assumeTrue(writer.supportsAsyncRetrieve());
@@ -362,7 +362,7 @@ void nonBlockingCleanShouldRemoveAllKeysByPattern() {
362362
connection.set("foo".getBytes(), "bar".getBytes());
363363
});
364364

365-
writer.clean(CACHE_NAME, (CACHE_NAME + "::*").getBytes(StandardCharsets.UTF_8));
365+
writer.clear(CACHE_NAME, (CACHE_NAME + "::*").getBytes(StandardCharsets.UTF_8));
366366

367367
doWithConnection(connection -> {
368368
Awaitility.await().pollInSameThread().pollDelay(Duration.ZERO).until(() -> !connection.exists(binaryCacheKey));

0 commit comments

Comments
 (0)