Remove phantom copy of expiring data when source gets persisted.

This commit makes sure to clean up resources when a previously expiring entity is persisted by setting the time to live to zero or negative.
In case a phantom copy exists for the changed entity, it is removed to free space on the server and prevent expiration events from being sent.

Closes #1955
Original Pull Request: #1961
This commit is contained in:
Muchnik Andrey
2021-02-08 21:18:54 +03:00
committed by Christoph Strobl
parent febdb82e58
commit e46246721f
2 changed files with 43 additions and 1 deletions

View File

@@ -99,6 +99,7 @@ import org.springframework.util.ObjectUtils;
*
* @author Christoph Strobl
* @author Mark Paluch
* @author Andrey Muchnik
* @since 1.7
*/
public class RedisKeyValueAdapter extends AbstractKeyValueAdapter
@@ -248,6 +249,11 @@ public class RedisKeyValueAdapter extends AbstractKeyValueAdapter
}
}
boolean isNoExpire = rdo.getTimeToLive() == null || rdo.getTimeToLive() != null && rdo.getTimeToLive() < 0;
if (isNoExpire && !isNew && keepShadowCopy()){
connection.del(ByteUtils.concat(objectKey, BinaryKeyspaceIdentifier.PHANTOM_SUFFIX));
}
connection.sAdd(toBytes(rdo.getKeyspace()), key);
IndexWriter indexWriter = new IndexWriter(connection, converter);
@@ -492,7 +498,7 @@ public class RedisKeyValueAdapter extends AbstractKeyValueAdapter
} else {
connection.persist(redisKey);
connection.persist(ByteUtils.concat(redisKey, BinaryKeyspaceIdentifier.PHANTOM_SUFFIX));
connection.del(ByteUtils.concat(redisKey, BinaryKeyspaceIdentifier.PHANTOM_SUFFIX));
}
}