It doesn't necessarily have to be a QuerySet; any function or method that takes some processing time could be decorated (e.g., an external call to an API). My aim is to reduce this code:
def do_some_processing():
cache_key = "key"
if cached_value := cache.get(cache_key):
return cached_value
fresh_value = do_some_computing()
cache.set(cached_value, fresh_value, 30)
return fresh_value
to this:
@cached_context("key", timeout=30)
def do_some_processing():
return do_some_computing()
AFAIK cache.set evaluates QuerySets, how would that be a problem?.
26 Ağustos 2022 Cuma tarihinde saat 12:24:39 UTC+3 itibarıyla Adam Johnson şunları yazdı: