Re: ZODB with Lazy evaluation / Caching / Data Flow programming

Tres Seaver <[email protected]> Fri, 27 Apr 2018 11:13:12 -0400
Newsgroups gmane.comp.web.zope.zodb
Message-ID <[email protected]>
On 04/27/2018 02:43 AM, Wong, Byron wrote:
> With regards to the consistency across computers issues -- yes in my case,
> it's fine that the read-only client are using a slightly stale data. In
> fact, that was the model in my previous company... from time to time, they
> will have to "refresh" the in-memory cache and ensure the state is
> consistent with that's in the database. I saw the YouTube demo on 2 Tier
> Kanban by Jim ... (this link
> https://www.youtube.com/watch?v=6v1sIw5j4ss&t=11s)  and see how new feature
> can automatically pop up after object being persisted in DB... that's seems
> pretty awesome, but my guess is without some proper listener logic, it's
> hard to achieve?

ZEO does propagate invalidation messages for objects modified in a
transaction.  I don't know from PythonFlow / MDF, but if you can arrange to
persist an "aggregate" object (think invoice) along with the "detail"
objects (think line items in the invoice), then you can store the cached
computations as what ZODB calls "volatile" attributes (those whose names
start with "_v_").  Volatile attributes are never persisted, and are
therefore discarded whenever their persistent instance is invalidated /
reloaded.  E.g.:

    class Invoice(Persistent):

        @property
        def subtotal(self):
            cached = getattr(self, '_v_subtotal', None)
            if cached is not None:
                return cached
            result = self._v_subtotal = self._compute_subtotal()
            return result

As long as the Invoice instance gets modified whenever one of its line
items is modified, you get the cache invalidation "for free" from ZODB.

If you can't persist the "aggregate" object, then you might need to use
some kind of pub-sub event notification to coordinate / distribute the
invalidations across hosts.


Tres.
-- 
===================================================================
Tres Seaver          +1 540-429-0999          [email protected]
Palladion Software   "Excellence by Design"    http://palladion.com

-- 
You received this message because you are subscribed to the Google Groups "zodb" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
For more options, visit https://groups.google.com/d/optout.