jedis icon indicating copy to clipboard operation
jedis copied to clipboard

client side cache is not invalidated upon key deletion from the same client

Open ArielBerkovich opened this issue 2 months ago • 1 comments

Expected behavior

When a client initiates the deletion of a key, and that key is cached by the client, the cache should be invalidated to prevent retaining invalid data.

Actual behavior

cache is not affected, attempting to get a cached value after its deletion returns it

Steps to reproduce:

run the following unit test:

    @Test
    public void test(){
        JedisClientConfig clientConfig = DefaultJedisClientConfig.builder()
                .resp3()
                .build();
        ClientSideCache clientSideCache =
                GuavaClientSideCache.builder().maximumSize(1000).build();
        UnifiedJedis jedis = new UnifiedJedis(new HostAndPort("127.0.0.1", 6379),
                clientConfig,clientSideCache);

        jedis.set("myKey","myValue");
        jedis.get("myKey"); // cache miss
        jedis.get("myKey"); // cache hit
        jedis.del("myKey");

        Assertions.assertNull(jedis.get("myKey")); 
    }

Jedis version:

5.2.0-beta1

ArielBerkovich avatar Apr 27 '24 17:04 ArielBerkovich

Client side caching does not guarantee immediate update. If you must have the updated data immediately, you should avoid client side caching.

sazzad16 avatar Apr 28 '24 08:04 sazzad16