On 03/05/12 16:38 +0200, Cédric Krier wrote:
> Last night, I got a talk with Nicolas about one issue we are going to
> face with the Active Record.
> Here is the explaination, the record instance (aka BrowseRecord) has a
> local_cache of some values read like xxx2xxx or function field.
> For xxx2xxx fields, we can not store in the global cache because there
> are references to the cursor, to the context etc.
> For function fields, we can not store it because the value may need to
> be recomputed.
> 
> The problem with AR willl be that as we pass record instance now
> everywhere (instead of id), the local cache of will almost never be
> cleared and so the developper will need to do it manually.  And this is
> not really a clean solution because it will be almost impossible to know
> when to clear the cache or not, so we will finally clear it at the begin
> of each methods and we will lose the advantage of AR.
> 
> So the idea will be to have an automatic clear of the cache when entering
> in a new method because inside a method the developper can now when to
> reset or not the cache.
> To do that, we thought about using `inspect` to retreive the stack and
> storing it in the local cache with the field value. Like that when we
> retrieve value from the cache, if the stack is not the same than we
> clear the cache.
> The main issue with this design is that inspect.currentframe [1] may not
> exist on other Python implementation. So the fallback will be to clear
> the cache anyway.
> 
> So what do you think?
> Is there anybody with a better idea?

I had a better idea :-)
Instead of using the stack, I propose to add a counter on the
Transaction that will count the create, write and delete calls.
So on the instance when filling the local cache, this counter will be
stored. Later when accessing the cache, the Transaction counter will be
compared to the instance one and if they are different, the local cache
is cleared.
I think it is a cleaner way to fix the issue.

-- 
Cédric Krier

B2CK SPRL
Rue de Rotterdam, 4
4000 Liège
Belgium
Tel: +32 472 54 46 59
Email/Jabber: [email protected]
Website: http://www.b2ck.com/

Attachment: pgpcC695M90qS.pgp
Description: PGP signature

Reply via email to