Memoize
NAME
Memoize - Make routines faster by trading space for time
SYNOPSIS
use v6;
use Memoize;
sub get-slowed-result(Int $n where $_ >= 0) is memoized {
sleep $n / 10;
return 1 if $n <= 1;
return get-slowed-result($n - 1) * $n;
}
say sprintf("get-slowed-result(%d) is %d", $_, get-slowed-result($_)) for 0..10;
DESCRIPTION
This make a Perl 6 routine faster by caching its results. This means it trades more memory space used to get less execution time on cache hits. This means it is faster on routines that return a result such the following:
An expensive calculation (CPU)
A slow database query (I/O)
This is a totally-experimental-at-the-moment module to create a subroutine trait similar to the currently experimental `is cached`.
OPTIONS
cache_size - Int (Default: 1000)
Define the cache size limitation on which cache eviction will occur. A bigger cache means faster.
strategy - Str (Default: LRU)
Define the cache eviction strategy. Only LRU (least recently used) is currently allowed.
pure - Bool (Default: True)
When this is enabled, is pure is implied on any 'is memoized' wrapped routine.
debug - Bool (Default: False)
Enable or disables verbose debugging. Not recommended to be True in production enviroments.