{
    "content": [
        {
            "type": "text",
            "text": "# Memoize (man)\n\n## NAME\n\nMemoize - Make functions faster by trading space for time\n\n## SYNOPSIS\n\n# This is the documentation for Memoize 1.03\nuse Memoize;\nmemoize('slowfunction');\nslowfunction(arguments);    # Is faster than it was before\nThis is normally all you need to know.  However, many options are available:\nmemoize(function, options...);\nOptions include:\nNORMALIZER => function\nINSTALL => newname\nSCALARCACHE => 'MEMORY'\nSCALARCACHE => ['HASH', \\%cachehash ]\nSCALARCACHE => 'FAULT'\nSCALARCACHE => 'MERGE'\nLISTCACHE => 'MEMORY'\nLISTCACHE => ['HASH', \\%cachehash ]\nLISTCACHE => 'FAULT'\nLISTCACHE => 'MERGE'\n\n## DESCRIPTION\n\n`Memoizing' a function makes it faster by trading space for time.  It does this by caching\nthe return values of the function in a table.  If you call the function again with the same\narguments, \"memoize\" jumps in and gives you the value out of the table, instead of letting\nthe function compute the value all over again.\n\n## Sections\n\n- **NAME**\n- **SYNOPSIS**\n- **DESCRIPTION**\n- **DETAILS**\n- **OPTIONS**\n- **OTHER FACILITIES** (1 subsections)\n- **CAVEATS**\n- **PERSISTENT CACHE SUPPORT**\n- **EXPIRATION SUPPORT**\n- **BUGS**\n- **MAILING LIST**\n- **AUTHOR**\n- **COPYRIGHT AND LICENSE**\n- **THANK YOU**\n\nUse structuredContent.sections for detailed options, examples, and full documentation.\n"
        }
    ],
    "structuredContent": {
        "command": "Memoize",
        "section": "",
        "mode": "man",
        "summary": "Memoize - Make functions faster by trading space for time",
        "synopsis": "# This is the documentation for Memoize 1.03\nuse Memoize;\nmemoize('slowfunction');\nslowfunction(arguments);    # Is faster than it was before\nThis is normally all you need to know.  However, many options are available:\nmemoize(function, options...);\nOptions include:\nNORMALIZER => function\nINSTALL => newname\nSCALARCACHE => 'MEMORY'\nSCALARCACHE => ['HASH', \\%cachehash ]\nSCALARCACHE => 'FAULT'\nSCALARCACHE => 'MERGE'\nLISTCACHE => 'MEMORY'\nLISTCACHE => ['HASH', \\%cachehash ]\nLISTCACHE => 'FAULT'\nLISTCACHE => 'MERGE'",
        "tldr_summary": null,
        "tldr_examples": [],
        "tldr_source": null,
        "flags": [],
        "examples": [],
        "see_also": [],
        "section_outline": [
            {
                "name": "NAME",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "SYNOPSIS",
                "lines": 24,
                "subsections": []
            },
            {
                "name": "DESCRIPTION",
                "lines": 69,
                "subsections": []
            },
            {
                "name": "DETAILS",
                "lines": 16,
                "subsections": []
            },
            {
                "name": "OPTIONS",
                "lines": 282,
                "subsections": []
            },
            {
                "name": "OTHER FACILITIES",
                "lines": 1,
                "subsections": [
                    {
                        "name": "\"unmemoize\"",
                        "lines": 29
                    }
                ]
            },
            {
                "name": "CAVEATS",
                "lines": 80,
                "subsections": []
            },
            {
                "name": "PERSISTENT CACHE SUPPORT",
                "lines": 37,
                "subsections": []
            },
            {
                "name": "EXPIRATION SUPPORT",
                "lines": 6,
                "subsections": []
            },
            {
                "name": "BUGS",
                "lines": 12,
                "subsections": []
            },
            {
                "name": "MAILING LIST",
                "lines": 3,
                "subsections": []
            },
            {
                "name": "AUTHOR",
                "lines": 15,
                "subsections": []
            },
            {
                "name": "COPYRIGHT AND LICENSE",
                "lines": 5,
                "subsections": []
            },
            {
                "name": "THANK YOU",
                "lines": 21,
                "subsections": []
            }
        ],
        "sections": {
            "NAME": {
                "content": "Memoize - Make functions faster by trading space for time\n",
                "subsections": []
            },
            "SYNOPSIS": {
                "content": "# This is the documentation for Memoize 1.03\nuse Memoize;\nmemoize('slowfunction');\nslowfunction(arguments);    # Is faster than it was before\n\nThis is normally all you need to know.  However, many options are available:\n\nmemoize(function, options...);\n\nOptions include:\n\nNORMALIZER => function\nINSTALL => newname\n\nSCALARCACHE => 'MEMORY'\nSCALARCACHE => ['HASH', \\%cachehash ]\nSCALARCACHE => 'FAULT'\nSCALARCACHE => 'MERGE'\n\nLISTCACHE => 'MEMORY'\nLISTCACHE => ['HASH', \\%cachehash ]\nLISTCACHE => 'FAULT'\nLISTCACHE => 'MERGE'\n",
                "subsections": []
            },
            "DESCRIPTION": {
                "content": "`Memoizing' a function makes it faster by trading space for time.  It does this by caching\nthe return values of the function in a table.  If you call the function again with the same\narguments, \"memoize\" jumps in and gives you the value out of the table, instead of letting\nthe function compute the value all over again.\n\nHere is an extreme example.  Consider the Fibonacci sequence, defined by the following\nfunction:\n\n# Compute Fibonacci numbers\nsub fib {\nmy $n = shift;\nreturn $n if $n < 2;\nfib($n-1) + fib($n-2);\n}\n\nThis function is very slow.  Why?  To compute fib(14), it first wants to compute fib(13) and\nfib(12), and add the results.  But to compute fib(13), it first has to compute fib(12) and\nfib(11), and then it comes back and computes fib(12) all over again even though the answer is\nthe same.  And both of the times that it wants to compute fib(12), it has to compute fib(11)\nfrom scratch, and then it has to do it again each time it wants to compute fib(13).  This\nfunction does so much recomputing of old results that it takes a really long time to\nrun---fib(14) makes 1,200 extra recursive calls to itself, to compute and recompute things\nthat it already computed.\n\nThis function is a good candidate for memoization.  If you memoize the `fib' function above,\nit will compute fib(14) exactly once, the first time it needs to, and then save the result in\na table.  Then if you ask for fib(14) again, it gives you the result out of the table.  While\ncomputing fib(14), instead of computing fib(12) twice, it does it once; the second time it\nneeds the value it gets it from the table.  It doesn't compute fib(11) four times; it\ncomputes it once, getting it from the table the next three times.  Instead of making 1,200\nrecursive calls to `fib', it makes 15.  This makes the function about 150 times faster.\n\nYou could do the memoization yourself, by rewriting the function, like this:\n\n# Compute Fibonacci numbers, memoized version\n{ my @fib;\nsub fib {\nmy $n = shift;\nreturn $fib[$n] if defined $fib[$n];\nreturn $fib[$n] = $n if $n < 2;\n$fib[$n] = fib($n-1) + fib($n-2);\n}\n}\n\nOr you could use this module, like this:\n\nuse Memoize;\nmemoize('fib');\n\n# Rest of the fib function just like the original version.\n\nThis makes it easy to turn memoizing on and off.\n\nHere's an even simpler example: I wrote a simple ray tracer; the program would look in a\ncertain direction, figure out what it was looking at, and then convert the `color' value\n(typically a string like `red') of that object to a red, green, and blue pixel value, like\nthis:\n\nfor ($direction = 0; $direction < 300; $direction++) {\n# Figure out which object is in direction $direction\n$color = $object->{color};\n($r, $g, $b) = @{&ColorToRGB($color)};\n...\n}\n\nSince there are relatively few objects in a picture, there are only a few colors, which get\nlooked up over and over again.  Memoizing \"ColorToRGB\" sped up the program by several\npercent.\n",
                "subsections": []
            },
            "DETAILS": {
                "content": "This module exports exactly one function, \"memoize\".  The rest of the functions in this\npackage are None of Your Business.\n\nYou should say\n\nmemoize(function)\n\nwhere \"function\" is the name of the function you want to memoize, or a reference to it.\n\"memoize\" returns a reference to the new, memoized version of the function, or \"undef\" on a\nnon-fatal error.  At present, there are no non-fatal errors, but there might be some in the\nfuture.\n\nIf \"function\" was the name of a function, then \"memoize\" hides the old version and installs\nthe new memoized version under the old name, so that \"&function(...)\" actually invokes the\nmemoized version.\n",
                "subsections": []
            },
            "OPTIONS": {
                "content": "There are some optional options you can pass to \"memoize\" to change the way it behaves a\nlittle.  To supply options, invoke \"memoize\" like this:\n\nmemoize(function, NORMALIZER => function,\nINSTALL => newname,\nSCALARCACHE => option,\nLISTCACHE => option\n);\n\nEach of these options is optional; you can include some, all, or none of them.\n\nINSTALL\nIf you supply a function name with \"INSTALL\", memoize will install the new, memoized version\nof the function under the name you give.  For example,\n\nmemoize('fib', INSTALL => 'fastfib')\n\ninstalls the memoized version of \"fib\" as \"fastfib\"; without the \"INSTALL\" option it would\nhave replaced the old \"fib\" with the memoized version.\n\nTo prevent \"memoize\" from installing the memoized version anywhere, use \"INSTALL => undef\".\n\nNORMALIZER\nSuppose your function looks like this:\n\n# Typical call: f('aha!', A => 11, B => 12);\nsub f {\nmy $a = shift;\nmy %hash = @;\n$hash{B} ||= 2;  # B defaults to 2\n$hash{C} ||= 7;  # C defaults to 7\n\n# Do something with $a, %hash\n}\n\nNow, the following calls to your function are all completely equivalent:\n\nf(OUCH);\nf(OUCH, B => 2);\nf(OUCH, C => 7);\nf(OUCH, B => 2, C => 7);\nf(OUCH, C => 7, B => 2);\n(etc.)\n\nHowever, unless you tell \"Memoize\" that these calls are equivalent, it will not know that,\nand it will compute the values for these invocations of your function separately, and store\nthem separately.\n\nTo prevent this, supply a \"NORMALIZER\" function that turns the program arguments into a\nstring in a way that equivalent arguments turn into the same string.  A \"NORMALIZER\" function\nfor \"f\" above might look like this:\n\nsub normalizef {\nmy $a = shift;\nmy %hash = @;\n$hash{B} ||= 2;\n$hash{C} ||= 7;\n\njoin(',', $a, map ($ => $hash{$}) sort keys %hash);\n}\n\nEach of the argument lists above comes out of the \"normalizef\" function looking exactly the\nsame, like this:\n\nOUCH,B,2,C,7\n\nYou would tell \"Memoize\" to use this normalizer this way:\n\nmemoize('f', NORMALIZER => 'normalizef');\n\n\"memoize\" knows that if the normalized version of the arguments is the same for two argument\nlists, then it can safely look up the value that it computed for one argument list and return\nit as the result of calling the function with the other argument list, even if the argument\nlists look different.\n\nThe default normalizer just concatenates the arguments with character 28 in between.  (In\nASCII, this is called FS or control-\\.)  This always works correctly for functions with only\none string argument, and also when the arguments never contain character 28.  However, it can\nconfuse certain argument lists:\n\nnormalizer(\"a\\034\", \"b\")\nnormalizer(\"a\", \"\\034b\")\nnormalizer(\"a\\034\\034b\")\n\nfor example.\n\nSince hash keys are strings, the default normalizer will not distinguish between \"undef\" and\nthe empty string.  It also won't work when the function's arguments are references.  For\nexample, consider a function \"g\" which gets two arguments: A number, and a reference to an\narray of numbers:\n\ng(13, [1,2,3,4,5,6,7]);\n\nThe default normalizer will turn this into something like \"13\\034ARRAY(0x436c1f)\".  That\nwould be all right, except that a subsequent array of numbers might be stored at a different\nlocation even though it contains the same data.  If this happens, \"Memoize\" will think that\nthe arguments are different, even though they are equivalent.  In this case, a normalizer\nlike this is appropriate:\n\nsub normalize { join ' ', $[0], @{$[1]} }\n\nFor the example above, this produces the key \"13 1 2 3 4 5 6 7\".\n\nAnother use for normalizers is when the function depends on data other than those in its\narguments.  Suppose you have a function which returns a value which depends on the current\nhour of the day:\n\nsub onduty {\nmy ($problemtype) = @;\nmy $hour = (localtime)[2];\nopen my $fh, \"$DIR/$problemtype\" or die...;\nmy $line;\nwhile ($hour-- > 0)\n$line = <$fh>;\n}\nreturn $line;\n}\n\nAt 10:23, this function generates the 10th line of a data file; at 3:45 PM it generates the\n15th line instead.  By default, \"Memoize\" will only see the $problemtype argument.  To fix\nthis, include the current hour in the normalizer:\n\nsub normalize { join ' ', (localtime)[2], @ }\n\nThe calling context of the function (scalar or list context) is propagated to the normalizer.\nThis means that if the memoized function will treat its arguments differently in list context\nthan it would in scalar context, you can have the normalizer function select its behavior\nbased on the results of \"wantarray\".  Even if called in a list context, a normalizer should\nstill return a single string.\n\n\"SCALARCACHE\", \"LISTCACHE\"\nNormally, \"Memoize\" caches your function's return values into an ordinary Perl hash variable.\nHowever, you might like to have the values cached on the disk, so that they persist from one\nrun of your program to the next, or you might like to associate some other interesting\nsemantics with the cached values.\n\nThere's a slight complication under the hood of \"Memoize\": There are actually two caches, one\nfor scalar values and one for list values.  When your function is called in scalar context,\nits return value is cached in one hash, and when your function is called in list context, its\nvalue is cached in the other hash.  You can control the caching behavior of both contexts\nindependently with these options.\n\nThe argument to \"LISTCACHE\" or \"SCALARCACHE\" must either be one of the following four\nstrings:\n\nMEMORY\nFAULT\nMERGE\nHASH\n\nor else it must be a reference to an array whose first element is one of these four strings,\nsuch as \"[HASH, arguments...]\".\n\n\"MEMORY\"\n\"MEMORY\" means that return values from the function will be cached in an ordinary Perl\nhash variable.  The hash variable will not persist after the program exits.  This is the\ndefault.\n\n\"HASH\"\n\"HASH\" allows you to specify that a particular hash that you supply will be used as the\ncache.  You can tie this hash beforehand to give it any behavior you want.\n\nA tied hash can have any semantics at all.  It is typically tied to an on-disk database,\nso that cached values are stored in the database and retrieved from it again when needed,\nand the disk file typically persists after your program has exited.  See \"perltie\" for\nmore complete details about \"tie\".\n\nA typical example is:\n\nuse DBFile;\ntie my %cache => 'DBFile', $filename, ORDWR|OCREAT, 0666;\nmemoize 'function', SCALARCACHE => [HASH => \\%cache];\n\nThis has the effect of storing the cache in a \"DBFile\" database whose name is in\n$filename.  The cache will persist after the program has exited.  Next time the program\nruns, it will find the cache already populated from the previous run of the program.  Or\nyou can forcibly populate the cache by constructing a batch program that runs in the\nbackground and populates the cache file.  Then when you come to run your real program the\nmemoized function will be fast because all its results have been precomputed.\n\nAnother reason to use \"HASH\" is to provide your own hash variable.  You can then inspect\nor modify the contents of the hash to gain finer control over the cache management.\n\n\"TIE\"\nThis option is no longer supported.  It is still documented only to aid in the debugging\nof old programs that use it.  Old programs should be converted to use the \"HASH\" option\ninstead.\n\nmemoize ... ['TIE', PACKAGE, ARGS...]\n\nis merely a shortcut for\n\nrequire PACKAGE;\n{ tie my %cache, PACKAGE, ARGS...;\nmemoize ... [HASH => \\%cache];\n}\n\n\"FAULT\"\n\"FAULT\" means that you never expect to call the function in scalar (or list) context, and\nthat if \"Memoize\" detects such a call, it should abort the program.  The error message is\none of\n\n`foo' function called in forbidden list context at line ...\n`foo' function called in forbidden scalar context at line ...\n\n\"MERGE\"\n\"MERGE\" normally means that the memoized function does not distinguish between list and\nsclar context, and that return values in both contexts should be stored together.  Both\n\"LISTCACHE => MERGE\" and \"SCALARCACHE => MERGE\" mean the same thing.\n\nConsider this function:\n\nsub complicated {\n# ... time-consuming calculation of $result\nreturn $result;\n}\n\nThe \"complicated\" function will return the same numeric $result regardless of whether it\nis called in list or in scalar context.\n\nNormally, the following code will result in two calls to \"complicated\", even if\n\"complicated\" is memoized:\n\n$x = complicated(142);\n($y) = complicated(142);\n$z = complicated(142);\n\nThe first call will cache the result, say 37, in the scalar cache; the second will cach\nthe list \"(37)\" in the list cache.  The third call doesn't call the real \"complicated\"\nfunction; it gets the value 37 from the scalar cache.\n\nObviously, the second call to \"complicated\" is a waste of time, and storing its return\nvalue is a waste of space.  Specifying \"LISTCACHE => MERGE\" will make \"memoize\" use the\nsame cache for scalar and list context return values, so that the second call uses the\nscalar cache that was populated by the first call.  \"complicated\" ends up being called\nonly once, and both subsequent calls return 3 from the cache, regardless of the calling\ncontext.\n\nList values in scalar context\n\nConsider this function:\n\nsub iota { return reverse (1..$[0]) }\n\nThis function normally returns a list.  Suppose you memoize it and merge the caches:\n\nmemoize 'iota', SCALARCACHE => 'MERGE';\n\n@i7 = iota(7);\n$i7 = iota(7);\n\nHere the first call caches the list (1,2,3,4,5,6,7).  The second call does not really make\nsense. \"Memoize\" cannot guess what behavior \"iota\" should have in scalar context without\nactually calling it in scalar context.  Normally \"Memoize\" would call \"iota\" in scalar\ncontext and cache the result, but the \"SCALARCACHE => 'MERGE'\" option says not to do that,\nbut to use the cache list-context value instead. But it cannot return a list of seven\nelements in a scalar context. In this case $i7 will receive the first element of the cached\nlist value, namely 7.\n\nMerged disk caches\n\nAnother use for \"MERGE\" is when you want both kinds of return values stored in the same disk\nfile; this saves you from having to deal with two disk files instead of one.  You can use a\nnormalizer function to keep the two sets of return values separate.  For example:\n\ntie my %cache => 'MLDBM', 'DBFile', $filename, ...;\n\nmemoize 'myfunc',\nNORMALIZER => 'n',\nSCALARCACHE => [HASH => \\%cache],\nLISTCACHE => 'MERGE',\n;\n\nsub n {\nmy $context = wantarray() ? 'L' : 'S';\n# ... now compute the hash key from the arguments ...\n$hashkey = \"$context:$hashkey\";\n}\n\nThis normalizer function will store scalar context return values in the disk file under keys\nthat begin with \"S:\", and list context return values under keys that begin with \"L:\".\n",
                "subsections": []
            },
            "OTHER FACILITIES": {
                "content": "",
                "subsections": [
                    {
                        "name": "\"unmemoize\"",
                        "content": "There's an \"unmemoize\" function that you can import if you want to.  Why would you want to?\nHere's an example: Suppose you have your cache tied to a DBM file, and you want to make sure\nthat the cache is written out to disk if someone interrupts the program.  If the program\nexits normally, this will happen anyway, but if someone types control-C or something then the\nprogram will terminate immediately without synchronizing the database.  So what you can do\ninstead is\n\n$SIG{INT} = sub { unmemoize 'function' };\n\n\"unmemoize\" accepts a reference to, or the name of a previously memoized function, and undoes\nwhatever it did to provide the memoized version in the first place, including making the name\nrefer to the unmemoized version if appropriate.  It returns a reference to the unmemoized\nversion of the function.\n\nIf you ask it to unmemoize a function that was never memoized, it croaks.\n\n\"flushcache\"\n\"flushcache(function)\" will flush out the caches, discarding all the cached data.  The\nargument may be a function name or a reference to a function.  For finer control over when\ndata is discarded or expired, see the documentation for \"Memoize::Expire\", included in this\npackage.\n\nNote that if the cache is a tied hash, \"flushcache\" will attempt to invoke the \"CLEAR\"\nmethod on the hash.  If there is no \"CLEAR\" method, this will cause a run-time error.\n\nAn alternative approach to cache flushing is to use the \"HASH\" option (see above) to request\nthat \"Memoize\" use a particular hash variable as its cache.  Then you can examine or modify\nthe hash at any time in any way you desire.  You may flush the cache by using \"%hash = ()\".\n"
                    }
                ]
            },
            "CAVEATS": {
                "content": "Memoization is not a cure-all:\n\n•   Do not memoize a function whose behavior depends on program state other than its own\narguments, such as global variables, the time of day, or file input.  These functions\nwill not produce correct results when memoized.  For a particularly easy example:\n\nsub f {\ntime;\n}\n\nThis function takes no arguments, and as far as \"Memoize\" is concerned, it always returns\nthe same result.  \"Memoize\" is wrong, of course, and the memoized version of this\nfunction will call \"time\" once to get the current time, and it will return that same time\nevery time you call it after that.\n\n•   Do not memoize a function with side effects.\n\nsub f {\nmy ($a, $b) = @;\nmy $s = $a + $b;\nprint \"$a + $b = $s.\\n\";\n}\n\nThis function accepts two arguments, adds them, and prints their sum.  Its return value\nis the numuber of characters it printed, but you probably didn't care about that.  But\n\"Memoize\" doesn't understand that.  If you memoize this function, you will get the result\nyou expect the first time you ask it to print the sum of 2 and 3, but subsequent calls\nwill return 1 (the return value of \"print\") without actually printing anything.\n\n•   Do not memoize a function that returns a data structure that is modified by its caller.\n\nConsider these functions:  \"getusers\" returns a list of users somehow, and then \"main\"\nthrows away the first user on the list and prints the rest:\n\nsub main {\nmy $userlist = getusers();\nshift @$userlist;\nforeach $u (@$userlist) {\nprint \"User $u\\n\";\n}\n}\n\nsub getusers {\nmy @users;\n# Do something to get a list of users;\n\\@users;  # Return reference to list.\n}\n\nIf you memoize \"getusers\" here, it will work right exactly once.  The reference to the\nusers list will be stored in the memo table.  \"main\" will discard the first element from\nthe referenced list.  The next time you invoke \"main\", \"Memoize\" will not call\n\"getusers\"; it will just return the same reference to the same list it got last time.\nBut this time the list has already had its head removed; \"main\" will erroneously remove\nanother element from it.  The list will get shorter and shorter every time you call\n\"main\".\n\nSimilarly, this:\n\n$u1 = getusers();\n$u2 = getusers();\npop @$u1;\n\nwill modify $u2 as well as $u1, because both variables are references to the same array.\nHad \"getusers\" not been memoized, $u1 and $u2 would have referred to different arrays.\n\n•   Do not memoize a very simple function.\n\nRecently someone mentioned to me that the Memoize module made his program run slower\ninstead of faster.  It turned out that he was memoizing the following function:\n\nsub square {\n$[0] * $[0];\n}\n\nI pointed out that \"Memoize\" uses a hash, and that looking up a number in the hash is\nnecessarily going to take a lot longer than a single multiplication.  There really is no\nway to speed up the \"square\" function.\n\nMemoization is not magical.\n",
                "subsections": []
            },
            "PERSISTENT CACHE SUPPORT": {
                "content": "You can tie the cache tables to any sort of tied hash that you want to, as long as it\nsupports \"TIEHASH\", \"FETCH\", \"STORE\", and \"EXISTS\".  For example,\n\ntie my %cache => 'GDBMFile', $filename, ORDWR|OCREAT, 0666;\nmemoize 'function', SCALARCACHE => [HASH => \\%cache];\n\nworks just fine.  For some storage methods, you need a little glue.\n\n\"SDBMFile\" doesn't supply an \"EXISTS\" method, so included in this package is a glue module\ncalled \"Memoize::SDBMFile\" which does provide one.  Use this instead of plain \"SDBMFile\" to\nstore your cache table on disk in an \"SDBMFile\" database:\n\ntie my %cache => 'Memoize::SDBMFile', $filename, ORDWR|OCREAT, 0666;\nmemoize 'function', SCALARCACHE => [HASH => \\%cache];\n\n\"NDBMFile\" has the same problem and the same solution.  (Use \"Memoize::NDBMFile instead of\nplain NDBMFile.\")\n\n\"Storable\" isn't a tied hash class at all.  You can use it to store a hash to disk and\nretrieve it again, but you can't modify the hash while it's on the disk.  So if you want to\nstore your cache table in a \"Storable\" database, use \"Memoize::Storable\", which puts a\nhashlike front-end onto \"Storable\".  The hash table is actually kept in memory, and is loaded\nfrom your \"Storable\" file at the time you memoize the function, and stored back at the time\nyou unmemoize the function (or when your program exits):\n\ntie my %cache => 'Memoize::Storable', $filename;\nmemoize 'function', SCALARCACHE => [HASH => \\%cache];\n\ntie my %cache => 'Memoize::Storable', $filename, 'nstore';\nmemoize 'function', SCALARCACHE => [HASH => \\%cache];\n\nInclude the `nstore' option to have the \"Storable\" database written in `network order'.  (See\nStorable for more details about this.)\n\nThe \"flushcache()\" function will raise a run-time error unless the tied package provides a\n\"CLEAR\" method.\n",
                "subsections": []
            },
            "EXPIRATION SUPPORT": {
                "content": "See Memoize::Expire, which is a plug-in module that adds expiration functionality to Memoize.\nIf you don't like the kinds of policies that Memoize::Expire implements, it is easy to write\nyour own plug-in module to implement whatever policy you desire.  Memoize comes with several\nexamples.  An expiration manager that implements a LRU policy is available on CPAN as\nMemoize::ExpireLRU.\n",
                "subsections": []
            },
            "BUGS": {
                "content": "The test suite is much better, but always needs improvement.\n\nThere is some problem with the way \"goto &f\" works under threaded Perl, perhaps because of\nthe lexical scoping of @.  This is a bug in Perl, and until it is resolved, memoized\nfunctions will see a slightly different \"caller()\" and will perform a little more slowly on\nthreaded perls than unthreaded perls.\n\nSome versions of \"DBFile\" won't let you store data under a key of length 0.  That means that\nif you have a function \"f\" which you memoized and the cache is in a \"DBFile\" database, then\nthe value of \"f()\" (\"f\" called with no arguments) will not be memoized.  If this is a big\nproblem, you can supply a normalizer function that prepends \"x\" to every key.\n",
                "subsections": []
            },
            "MAILING LIST": {
                "content": "To join a very low-traffic mailing list for announcements about \"Memoize\", send an empty note\nto \"mjd-perl-memoize-request@plover.com\".\n",
                "subsections": []
            },
            "AUTHOR": {
                "content": "Mark-Jason Dominus (\"mjd-perl-memoize+@plover.com\"), Plover Systems co.\n\nSee the \"Memoize.pm\" Page at http://perl.plover.com/Memoize/ for news and upgrades.  Near\nthis page, at http://perl.plover.com/MiniMemoize/ there is an article about memoization and\nabout the internals of Memoize that appeared in The Perl Journal, issue #13.  (This article\nis also included in the Memoize distribution as `article.html'.)\n\nThe author's book Higher-Order Perl (2005, ISBN 1558607013, published by Morgan Kaufmann)\ndiscusses memoization (and many other topics) in tremendous detail. It is available on-line\nfor free.  For more information, visit http://hop.perl.plover.com/ .\n\nTo join a mailing list for announcements about \"Memoize\", send an empty message to\n\"mjd-perl-memoize-request@plover.com\".  This mailing list is for announcements only and has\nextremely low traffic---fewer than two messages per year.\n",
                "subsections": []
            },
            "COPYRIGHT AND LICENSE": {
                "content": "Copyright 1998, 1999, 2000, 2001, 2012  by Mark Jason Dominus\n\nThis library is free software; you may redistribute it and/or modify it under the same terms\nas Perl itself.\n",
                "subsections": []
            },
            "THANK YOU": {
                "content": "Many thanks to Florian Ragwitz for administration and packaging assistance, to John Tromp for\nbug reports, to Jonathan Roy for bug reports and suggestions, to Michael Schwern for other\nbug reports and patches, to Mike Cariaso for helping me to figure out the Right Thing to Do\nAbout Expiration, to Joshua Gerth, Joshua Chamas, Jonathan Roy (again), Mark D. Anderson, and\nAndrew Johnson for more suggestions about expiration, to Brent Powers for the\nMemoize::ExpireLRU module, to Ariel Scolnicov for delightful messages about the Fibonacci\nfunction, to Dion Almaer for thought-provoking suggestions about the default normalizer, to\nWalt Mankowski and Kurt Starsinic for much help investigating problems under threaded Perl,\nto Alex Dudkevich for reporting the bug in prototyped functions and for checking my patch, to\nTony Bass for many helpful suggestions, to Jonathan Roy (again) for finding a use for\n\"unmemoize()\", to Philippe Verdret for enlightening discussion of \"Hook::PrePostCall\", to Nat\nTorkington for advice I ignored, to Chris Nandor for portability advice, to Randal Schwartz\nfor suggesting the '\"flushcache\" function, and to Jenda Krynicky for being a light in the\nworld.\n\nSpecial thanks to Jarkko Hietaniemi, the 5.8.0 pumpking, for including this module in the\ncore and for his patient and helpful guidance during the integration process.\n\n\n\nperl v5.34.0                                 2025-07-25                               Memoize(3perl)",
                "subsections": []
            }
        }
    }
}