Re: A generic cache decorator around low level cache api

2023-01-02 Thread suayip uzulmez
I would like to see more opinions on this, I am using this type of utility 
in almost every project I make and it seems to me it would a decent utility 
function.

26 Ağustos 2022 Cuma tarihinde saat 14:45:13 UTC+3 itibarıyla suayip 
uzulmez şunları yazdı:

> 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ı:
>
>> I'm not sure I quite understand your proposal. Are you suggesting a 
>> decorator that caches the results of every queryset that is resolved within 
>> the decorated function?
>>
>> If so, I'm not sure how useful it would be. First, if a single query is 
>> problematic, there’s normally a way to optimize it within the database - 
>> for example, a materialized view allows you to “cache” query results and 
>> recompute them in the background. Second, QuerySets are lazy, so it could 
>> be surprising to decorate a function that returns a QuerySet that is not 
>> yet resolved.
>>
>> On Wed, Aug 24, 2022 at 3:49 PM suayip uzulmez  
>> wrote:
>>
>>> Usually, I need to construct a simple cache pipeline to optimize 
>>> database access using low-level cache API (django.core.cache).
>>>
>>> I think we could use a decorator as such to ease this process:
>>>
>>> cached_context(key, *, timeout, cache)
>>>
>>> I know higher-level utilities exist such as cache_page, however I think 
>>> the decorator above provides more granularity over what to cache. For 
>>> example, I usually need such decorator in model methods where I do some 
>>> database aggregation operations based on the instance.
>>>
>>> What do you think?
>>>
>>> -- 
>>> You received this message because you are subscribed to the Google 
>>> Groups "Django developers (Contributions to Django itself)" group.
>>> To unsubscribe from this group and stop receiving emails from it, send 
>>> an email to django-develop...@googlegroups.com.
>>> To view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/django-developers/facbcfa8-2404-4dc6-b56d-eb0f25ba491cn%40googlegroups.com
>>>  
>>> 
>>> .
>>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/df61bbf0-e0b3-41aa-beba-d343fe6685a6n%40googlegroups.com.


Re: models.CalculatedField feature

2023-01-02 Thread Jeremy Nauta
FYI I have posted a tentative first draft of this feature, feedback is 
greatly appreciated!

https://github.com/django/django/pull/16417
https://code.djangoproject.com/ticket/31300

On Saturday, February 3, 2018 at 5:06:08 p.m. UTC-7 raider...@gmail.com 
wrote:

> Hey, 
>
> So has this stalled? Because this looked really great, and I was looking 
> forward to seeing it!
>
>
> On Monday, November 20, 2017 at 10:31:31 PM UTC-5, 
> ilya.ka...@jetbrains.com wrote:
>
>> Thank you all.
>>
>> I've created a feature request 
>> https://code.djangoproject.com/ticket/28822 and will try to implement in 
>> my Django fork next week. I am not Django source code guru, so any help is 
>> welcome:)
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/6b2c9692-390f-41b0-96d0-eab170cdb15dn%40googlegroups.com.