Does Django open and close connection to cache every time I call cache.delete(key)?

229 Views Asked by At

Consider the following code snippet:

from django.core.cache import cache

cache.delete('key_1')
cache.delete('key_2')

If i'm using an Instance of Redis as my default cache, will Django create two seperate connections to the Redis instance, for each call to .delete()? or will it keep a single connection open to fulfil both calls to .delete()?

I have a circumstance where I may need to delete a lot of individual keys in one go.

Ideally I would like a single connection to the Redis cache to persist, rather than take on the latency of creating a new connection each time a cache method is called.

Thanks

0

There are 0 best solutions below