I&#39;m trying to avoid some unnecessary computation, and I feel I must be missing something, either in terms of Trellis API or approach to the problem.<br><br clear="all">I have a value y which depends on x.&nbsp; x would be a trellis managed piece of data.&nbsp; The computation of y from x is expensive.<br>
<br>Right now, I have a pattern something like:<br><br>class A(object):<br>&nbsp;&nbsp;&nbsp; x = None<br>&nbsp;&nbsp;&nbsp; last_x = None<br>&nbsp;&nbsp;&nbsp; last_y = None<br>&nbsp;&nbsp;&nbsp; @property<br>&nbsp;&nbsp;&nbsp; def y(self):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if self.x != self.last_x:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.last_y = some_expensive_calculation(self.x)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return self.last_y<br><br>I would like to accomplish something equivalent with Trellis attributes or Cells, so that I don&#39;t have to repeat the computation unless the computed value would change.&nbsp; Using a maintenance rule, y would be recomputed every time some dependency in x changed.&nbsp; Using a compute rule, y is recomputed every time I access y.&nbsp; My goal is to be able to set x some number of times, followed by accessing y some number of times, but only ever do the calculation once.&nbsp; I realize that this effect may be achieved by an optional maintenance rule, but I&#39;d like the same effect for every set of x and every access of y, not just the first access of y.<br>
<br>-- <br>Christopher Stelma<br><a href="mailto:chris@digsby.com" target="_blank">chris@digsby.com</a><br>