Bypassing cache for function field.

Skip to first unread message

Jon Levy

Aug 2, 2018, 5:19:17 PM8/2/18
to tryton
When a function field is accessed multiple times without there being any database operations, it will be calculated the first time, cached, and subsequently recalled out of cache.

The only way to prevent this that I can find (without messing with internals) is to do a database operation (and thus increment the transaction counter), signaling to the numerous caches that they should clear.

Of course, explicitly changing the transaction counter would also accomplish the aim. Does anyone know if this is acceptable?

I understand that I should probably not even be talking about such things. Why would the function field have changed without a database operation? I am in a strange case where I have a function field that is used to generate a report, but new legal guidance has been issued that creates two interpretations of how that function field might be calculated. I have a wizard that runs a series of reports, and the idea is to now have two versions of the report: one for each method of calculating the function field (based on a context flag). I understand that this is not great, and that idiomatically the better thing to do would be to either convert the function field into a regular python method, or use two different function fields. I am just not investing the time to do that yet--in part because I think there is a good possibility of new legal guidance coming out fairly soon.

Any advice on how to not use the cache? (Btw, the avenue of doing a trivial database operation to increment the counter also runs into problems because reports are run in readonly transactions.)

Cédric Krier

Aug 2, 2018, 6:25:06 PM8/2/18
to tryton
As you said that your computation depend on the context, you should
instantiate the record with each context. This way the computation will
be redone.

Cédric Krier - B2CK SPRL
Tel: +32 472 54 46 59

Jon Levy

Aug 9, 2018, 9:45:09 AM8/9/18
to tryton
On Thursday, August 2, 2018 at 6:25:06 PM UTC-4, Cédric Krier wrote:
> . . . you should
> instantiate the record with each context. This way the computation will
> be redone.

Perfect. Thanks.
Reply all
Reply to author
0 new messages