Your opinion on a practice to generate cache

Good morning,

I wonder about a practice I saw on some forums to generate cache.

Simply specify the function name in the view before the variable as follows:

And thanks to this you can recall a loaded variable without having to regenerate it.
Is this a common practice? Is it viable?

Thank you in advance for your feedback.

That’s not “cache”.

A function is an object. Try this in the Python shell:

def a():


All you’re doing with that is assigning an attribute to that object.

In Django? Not at the “application” layer, no.

You’d need to be a lot more specific about what exactly you’re trying to do with that to answer that question.

Keep in mind that in a production environment, classes are shared between requests - but not shared between processes. Keeping those types of values synchronized between worker processes would be a lot more effort than it’s worth.