File tree Expand file tree Collapse file tree 1 file changed +14
-4
lines changed Expand file tree Collapse file tree 1 file changed +14
-4
lines changed Original file line number Diff line number Diff line change @@ -63,11 +63,21 @@ Returns C<True> if the routine is a stub
63
63
64
64
multi sub trait_mod:<is>(Routine $r, :$cached!)
65
65
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 .
69
69
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
71
81
72
82
= begin code
73
83
use v6;
You can’t perform that action at this time.
0 commit comments