From: "Shot (Piotr Szotkowski)" Date: 2008-02-21T19:01:40+09:00 Subject: Re: Object#freeze as a basis for caching of method results? --94F+iWR2g9UqwGme Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Robert Klemme: > An alternative approach would be to use current state as cache key, > i.e. create an immutable copy and stuff that along with calculation > results into a Hash. What would you say about the following approach? I=E2=80=99m not sure it sc= ales well, but seems to work properly, have the smallest diff impact on the existing codebase and take object state into account=E2=80=A6 shot@devielle:~/work/PhD/bzr/trunk$ bzr diff =3D=3D=3D modified file 'trunk/lib/art-decomp/fsm.rb' --- trunk/lib/art-decomp/fsm.rb 2008-02-17 21:36:39 +0000 +++ trunk/lib/art-decomp/fsm.rb 2008-02-21 09:03:53 +0000 @@ -1,5 +1,7 @@ class ArtDecomp::FSM < ArtDecomp::TruthTable =20 + @@cache =3D Hash.new { |hash, key| hash[key] =3D {} } + attr_accessor :q, :qp =20 def self.from_kiss string @@ -31,7 +33,7 @@ end =20 def beta_f - outputs.to_blanket + @@cache[Marshal.dump self][:beta_f] ||=3D outputs.to_blanket end =20 def beta_q -- Shot --=20 So the Ether Bunny goes hippety hopity down the garden path, waylaying innocent fieldmice and anesthetising them, so he can sell their teeth to the Tooth Fairy to support his milk-and-cookies habit. --94F+iWR2g9UqwGme Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.2.2 (GNU/Linux) iD8DBQFHvUSXi/mCfdEo8UoRAgkXAJ4qY9Wqw+WDeg8x9KIJBA6mztdHQACgwZBz 4+ZGtLkTWIL0fU4Qk/AJGOo= =5ROh -----END PGP SIGNATURE----- --94F+iWR2g9UqwGme--