Skip to content

Commit 28d7b8f

Browse files
author
Carl Masak
committed
rewrite the 'is cached' section
Based on feedback from smls++
1 parent 394fc0b commit 28d7b8f

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

lib/Type/Routine.pod

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,21 @@ Returns C<True> if the routine is a stub
6363
6464
multi sub trait_mod:<is>(Routine $r, :$cached!)
6565
66-
Caches the return value of a routine, which means that when several calls with
67-
the same argument lists are performed, only the first one actually calls the
68-
routine, and subsequent calls retrieve the return value from the cache.
66+
Causes the return value of a routine to be stored, so that when subsequent
67+
calls with the same list of arguments are made, the stored value can be
68+
returned immediately instead of re-running the routine.
6969
70-
This makes only sense for routines that retrieve value types ase arguments.
70+
Useful when storing and returning the computed value is much faster than
71+
re-computing it every time, and when the time saving trumps the cost of the
72+
use of more memory.
73+
74+
Even if the arguments passed to the routine are "reference types" (such as
75+
objects or arrays), then for the purpose of caching they will only be compared
76+
based on their contents. Thus the second invocation will hit the cache in this
77+
case:
78+
79+
say foo( [1, 2, 3] ); # runs foo
80+
say foo( [1, 2, 3] ); # doesn't run foo, uses cached value
7181
7282
=begin code
7383
use v6;

0 commit comments

Comments
 (0)