Cache

 add a temporary entry to the cache table

 Calling Sequence AddTemporary( cache, key, value )

Parameters

 cache - cache table or procedure: the object in which to insert the entry key - list: the key to add value - anything: the value to associate with key

Description

 • The AddTemporary command creates a temporary entry associating key with value in a cache table.  The cache table can be given directly as cache, or cache can refer to a procedure that has, or can have, a cache remember table.  If such a procedure is given and it has a cache remember table, the temporary entry is inserted into that table. Otherwise, a new cache table is created, installed as cache's remember table and the temporary entry is inserted into that table.
 • To handle an expression sequence as a key, key must be given in a list.  The actual key used for the entry is op(key).
 • If more than one argument is passed after key, then an expression sequence containing those arguments is used as value.
 • Assigning directly into a cache table, using the cache[key] := value notation, creates a temporary entry.  As well, a function with option cache creates a temporary entry when the function is called. Calling AddPermanent is the only way to create a permanent entry into a cache table.
 • To remove a temporary entry from a cache table use RemoveTemporary.
 • Creating a temporary entry for a key that already has a permanent entry is not an error.  In this case, the temporary entry is used.

Examples

 > $\mathrm{c1}≔\mathrm{Cache}\left(\right)$
 ${\mathrm{c1}}{≔}{\mathrm{Cache}}{}\left({512}\right)$ (1)
 > $\mathrm{c1}\left[a\right]≔b$
 ${{\mathrm{c1}}}_{{a}}{≔}{b}$ (2)
 > $\mathrm{Cache}:-\mathrm{AddTemporary}\left(\mathrm{c1},\left[x\right],y\right)$
 > $\mathrm{Cache}:-\mathrm{AddTemporary}\left(\mathrm{c1},\left[y\right],z\right)$
 > $\mathrm{eval}\left(\mathrm{c1}\right)$
 ${\mathrm{Cache}}{}\left({512}{,}'{\mathrm{temporary}}'{=}\left[{a}{=}{b}{,}{x}{=}{y}{,}{y}{=}{z}\right]\right)$ (3)
 > p := proc(x,y) option cache; x+y; end proc;
 ${p}{≔}{\mathbf{proc}}\left({x}{,}{y}\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{option}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathrm{cache}}{;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{x}{+}{y}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{end proc}}$ (4)
 > $p\left(1,1\right)$
 ${2}$ (5)
 > $\mathrm{Cache}:-\mathrm{AddTemporary}\left(p,\left[2,2\right],8\right)$
 > $\mathrm{Cache}:-\mathrm{AddTemporary}\left(p,\left[1,2\right],5\right)$
 > $p\left(2,2\right)$
 ${8}$ (6)
 > $p\left(1,2\right)$
 ${5}$ (7)
 > $\mathrm{Cache}:-\mathrm{AddPermanent}\left(p,\left[3,3\right],5,6,7\right)$
 > $p\left(2,2\right)$
 ${8}$ (8)
 > $\mathrm{op}\left(4,\mathrm{eval}\left(p\right)\right)$
 ${\mathrm{Cache}}{}\left({512}{,}'{\mathrm{temporary}}'{=}\left[\left({1}{,}{1}\right){=}{2}{,}\left({2}{,}{2}\right){=}{8}{,}\left({1}{,}{2}\right){=}{5}\right]{,}'{\mathrm{permanent}}'{=}\left[\left({3}{,}{3}\right){=}\left({5}{,}{6}{,}{7}\right)\right]\right)$ (9)