<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: A Better Javascript Memoizer</title>
	<atom:link href="http://unscriptable.com/index.php/2009/05/01/a-better-javascript-memoizer/feed/" rel="self" type="application/rss+xml" />
	<link>http://unscriptable.com/index.php/2009/05/01/a-better-javascript-memoizer/</link>
	<description>Nothing is impossible.  Even on the Web.</description>
	<lastBuildDate>Mon, 28 Jun 2010 22:12:59 -0400</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: A Better Javascript Un-memoizer. Part 1: Epic FAIL! &#124; Unscriptable.com</title>
		<link>http://unscriptable.com/index.php/2009/05/01/a-better-javascript-memoizer/comment-page-1/#comment-1100</link>
		<dc:creator>A Better Javascript Un-memoizer. Part 1: Epic FAIL! &#124; Unscriptable.com</dc:creator>
		<pubDate>Wed, 28 Apr 2010 20:41:04 +0000</pubDate>
		<guid isPermaLink="false">http://unscriptable.com/?p=272#comment-1100</guid>
		<description>[...] my previous post, A Better Javascript Memoizer, some of you left some great feedback. (Thanks to all of you!) I think it&#8217;s because each of [...]</description>
		<content:encoded><![CDATA[<p>[...] my previous post, A Better Javascript Memoizer, some of you left some great feedback. (Thanks to all of you!) I think it&#8217;s because each of [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: uberVU - social comments</title>
		<link>http://unscriptable.com/index.php/2009/05/01/a-better-javascript-memoizer/comment-page-1/#comment-867</link>
		<dc:creator>uberVU - social comments</dc:creator>
		<pubDate>Sun, 31 Jan 2010 13:45:29 +0000</pubDate>
		<guid isPermaLink="false">http://unscriptable.com/?p=272#comment-867</guid>
		<description>&lt;strong&gt;Social comments and analytics for this post...&lt;/strong&gt;

This post was mentioned on Twitter by major_code: http://tinyurl.com/cwomvm 
A Better Javascript Memoizer &#124; Unscriptable.com...</description>
		<content:encoded><![CDATA[<p><strong>Social comments and analytics for this post&#8230;</strong></p>
<p>This post was mentioned on Twitter by major_code: <a href="http://tinyurl.com/cwomvm" rel="nofollow">http://tinyurl.com/cwomvm</a><br />
A Better Javascript Memoizer | Unscriptable.com&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: fogus</title>
		<link>http://unscriptable.com/index.php/2009/05/01/a-better-javascript-memoizer/comment-page-1/#comment-533</link>
		<dc:creator>fogus</dc:creator>
		<pubDate>Fri, 15 May 2009 17:18:44 +0000</pubDate>
		<guid isPermaLink="false">http://unscriptable.com/?p=272#comment-533</guid>
		<description>You can make this work for functions with arity 0 by changing the last two lines to:

&lt;pre&gt;
    var arity = func.arity &#124;&#124; func.length;
    return memoizeArg(arity ? arity - 1 : 0);
&lt;/pre&gt;

-m</description>
		<content:encoded><![CDATA[<p>You can make this work for functions with arity 0 by changing the last two lines to:</p>
<pre>
    var arity = func.arity || func.length;
    return memoizeArg(arity ? arity - 1 : 0);
</pre>
<p>-m</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John H</title>
		<link>http://unscriptable.com/index.php/2009/05/01/a-better-javascript-memoizer/comment-page-1/#comment-531</link>
		<dc:creator>John H</dc:creator>
		<pubDate>Fri, 15 May 2009 03:48:29 +0000</pubDate>
		<guid isPermaLink="false">http://unscriptable.com/?p=272#comment-531</guid>
		<description>Hey Simon,

On the surface, Nicolas&#039; implementation looks good, but it&#039;s not robust.  Here&#039;s why:

1. It adds properties to the function instance, f.&lt;/li&gt;
2. &lt;code&gt;args.toString()&lt;/code&gt; is not guaranteed to be unique for all combinations of arguments.

Regarding the first point, any general-purpose function should avoid interfering with other code as much as possible.  By assigning properties to the function instance, you have limited the calling code from using a similarly-named property on the function instance.  This may seem like a minor point, but if all general-purpose functions worked this way, we&#039;d eventually encounter conflicts &#8212; and this would result in some really nasty debugging sessions.

The second point is much more important.  All Javascript property names must be strings, so the array is serialized to a string when it is used as a property name (&lt;code&gt;f.memoized[args]&lt;/code&gt;).  In Javascript, Arrays serialze to a CSV-like representation.  For example, [1, 2, 3, &#039;foo&#039;] will serialize to &quot;1,2,3,foo&quot;.  This becomes a problem when objects are introduced &#8212; or even strings containing commas.  Here&#039;s what you&#039;d get when you pass the following arguments:

[1, &#039;commas,are,in,here&#039;, {foo: &#039;bar&#039;}] &#8658; &quot;1,commas,are,in,here,[object Object]&quot;

Unfortunately, the following arguments yield the same exact property name when serialized:

[1, &#039;commas&#039;, &#039;are&#039;, &#039;in&#039;, &#039;here&#039;, {prop: &#039;val&#039;}] &#8658; &quot;1,commas,are,in,here,[object Object]&quot;</description>
		<content:encoded><![CDATA[<p>Hey Simon,</p>
<p>On the surface, Nicolas&#8217; implementation looks good, but it&#8217;s not robust.  Here&#8217;s why:</p>
<p>1. It adds properties to the function instance, f.<br />
2. <code>args.toString()</code> is not guaranteed to be unique for all combinations of arguments.</p>
<p>Regarding the first point, any general-purpose function should avoid interfering with other code as much as possible.  By assigning properties to the function instance, you have limited the calling code from using a similarly-named property on the function instance.  This may seem like a minor point, but if all general-purpose functions worked this way, we&#8217;d eventually encounter conflicts &mdash; and this would result in some really nasty debugging sessions.</p>
<p>The second point is much more important.  All Javascript property names must be strings, so the array is serialized to a string when it is used as a property name (<code>f.memoized[args]</code>).  In Javascript, Arrays serialze to a CSV-like representation.  For example, [1, 2, 3, 'foo'] will serialize to &#8220;1,2,3,foo&#8221;.  This becomes a problem when objects are introduced &mdash; or even strings containing commas.  Here&#8217;s what you&#8217;d get when you pass the following arguments:</p>
<p>[1, 'commas,are,in,here', {foo: 'bar'}] &rArr; &#8220;1,commas,are,in,here,[object Object]&#8221;</p>
<p>Unfortunately, the following arguments yield the same exact property name when serialized:</p>
<p>[1, 'commas', 'are', 'in', 'here', {prop: 'val'}] &rArr; &#8220;1,commas,are,in,here,[object Object]&#8220;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Simon</title>
		<link>http://unscriptable.com/index.php/2009/05/01/a-better-javascript-memoizer/comment-page-1/#comment-530</link>
		<dc:creator>Simon</dc:creator>
		<pubDate>Thu, 14 May 2009 13:58:07 +0000</pubDate>
		<guid isPermaLink="false">http://unscriptable.com/?p=272#comment-530</guid>
		<description>The most elegant example I have ever seen is:

&lt;pre&gt;
function memoize(f) {
  return function () {
      var args = Array.prototype.slice.call(arguments);
      f.memoized = f.memoized &#124;&#124; {};
      return (args in f.memoized) ?
        f.memoized[args] :
        f.memoized[args] = f.apply(this, args);
  };
}
&lt;/pre&gt;
Courtesy of http://blog.thejit.org/</description>
		<content:encoded><![CDATA[<p>The most elegant example I have ever seen is:</p>
<pre>
function memoize(f) {
  return function () {
      var args = Array.prototype.slice.call(arguments);
      f.memoized = f.memoized || {};
      return (args in f.memoized) ?
        f.memoized[args] :
        f.memoized[args] = f.apply(this, args);
  };
}
</pre>
<p>Courtesy of <a href="http://blog.thejit.org/" rel="nofollow">http://blog.thejit.org/</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: links for 2009-05-12 &#124; hooker headers</title>
		<link>http://unscriptable.com/index.php/2009/05/01/a-better-javascript-memoizer/comment-page-1/#comment-529</link>
		<dc:creator>links for 2009-05-12 &#124; hooker headers</dc:creator>
		<pubDate>Thu, 14 May 2009 01:53:45 +0000</pubDate>
		<guid isPermaLink="false">http://unscriptable.com/?p=272#comment-529</guid>
		<description>[...] A Better Javascrip&amp;#116&amp;#32&amp;#77emoizer Yes, memoization is a neat concept. But wh&amp;#121&amp;#32&amp;#117se it rather than just hand-coded caching mechanis&amp;#109&amp;#115&amp;#63 It’s easy enough to write a caching routine, ri&amp;#103&amp;#104&amp;#116? Here are [...]</description>
		<content:encoded><![CDATA[<p>[...] A Better Javascrip&#116&#32&#77emoizer Yes, memoization is a neat concept. But wh&#121&#32&#117se it rather than just hand-coded caching mechanis&#109&#115&#63 It’s easy enough to write a caching routine, ri&#103&#104&#116? Here are [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Oslo Mosquito raid &#187; Paris–Harrington theorem</title>
		<link>http://unscriptable.com/index.php/2009/05/01/a-better-javascript-memoizer/comment-page-1/#comment-528</link>
		<dc:creator>Oslo Mosquito raid &#187; Paris–Harrington theorem</dc:creator>
		<pubDate>Tue, 12 May 2009 23:25:35 +0000</pubDate>
		<guid isPermaLink="false">http://unscriptable.com/?p=272#comment-528</guid>
		<description>[...] A Better Javascript Memoizer &#124; Unscriptable.com [...]</description>
		<content:encoded><![CDATA[<p>[...] A Better Javascript Memoizer | Unscriptable.com [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: links for 2009-05-12 &#171; boblog</title>
		<link>http://unscriptable.com/index.php/2009/05/01/a-better-javascript-memoizer/comment-page-1/#comment-527</link>
		<dc:creator>links for 2009-05-12 &#171; boblog</dc:creator>
		<pubDate>Tue, 12 May 2009 10:18:17 +0000</pubDate>
		<guid isPermaLink="false">http://unscriptable.com/?p=272#comment-527</guid>
		<description>[...] A Better Javascript Memoizer Yes, memoization is a neat concept. But why use it rather than just hand-coded caching mechanisms? It’s easy enough to write a caching routine, right? Here are a few good reasons: [...]</description>
		<content:encoded><![CDATA[<p>[...] A Better Javascript Memoizer Yes, memoization is a neat concept. But why use it rather than just hand-coded caching mechanisms? It’s easy enough to write a caching routine, right? Here are a few good reasons: [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John H</title>
		<link>http://unscriptable.com/index.php/2009/05/01/a-better-javascript-memoizer/comment-page-1/#comment-526</link>
		<dc:creator>John H</dc:creator>
		<pubDate>Mon, 11 May 2009 20:38:39 +0000</pubDate>
		<guid isPermaLink="false">http://unscriptable.com/?p=272#comment-526</guid>
		<description>@Nick: I really like the way it uses the &quot;property&quot; to invalidate / reset the cache!  That is neat.  That gives me some ideas.... hm....</description>
		<content:encoded><![CDATA[<p>@Nick: I really like the way it uses the &#8220;property&#8221; to invalidate / reset the cache!  That is neat.  That gives me some ideas&#8230;. hm&#8230;.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nick</title>
		<link>http://unscriptable.com/index.php/2009/05/01/a-better-javascript-memoizer/comment-page-1/#comment-524</link>
		<dc:creator>Nick</dc:creator>
		<pubDate>Mon, 11 May 2009 02:38:02 +0000</pubDate>
		<guid isPermaLink="false">http://unscriptable.com/?p=272#comment-524</guid>
		<description>SproutCore 1.0 now has built in memoization. Basically, this is all you need to do:

function() {
  // some heavy function call/logic
}.property(&#039;myName&#039;).cacheable()

The .property() call ensures that if &#039;myName&#039; changes, the cache invalidates. Also, there is an external call for expiring cache if needed...

Pretty neat, huh?</description>
		<content:encoded><![CDATA[<p>SproutCore 1.0 now has built in memoization. Basically, this is all you need to do:</p>
<p>function() {<br />
  // some heavy function call/logic<br />
}.property(&#8217;myName&#8217;).cacheable()</p>
<p>The .property() call ensures that if &#8216;myName&#8217; changes, the cache invalidates. Also, there is an external call for expiring cache if needed&#8230;</p>
<p>Pretty neat, huh?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: The Ashes &#187; Blog Archive &#187; A Better Javascript Memoizer</title>
		<link>http://unscriptable.com/index.php/2009/05/01/a-better-javascript-memoizer/comment-page-1/#comment-522</link>
		<dc:creator>The Ashes &#187; Blog Archive &#187; A Better Javascript Memoizer</dc:creator>
		<pubDate>Sun, 10 May 2009 14:32:42 +0000</pubDate>
		<guid isPermaLink="false">http://unscriptable.com/?p=272#comment-522</guid>
		<description>[...] have covered memoizers in the past, but John Hann has posted on a nice implementation that takes advantage of closures, arity, and recursion &#8212; 3 concepts/features that Javascript [...]</description>
		<content:encoded><![CDATA[<p>[...] have covered memoizers in the past, but John Hann has posted on a nice implementation that takes advantage of closures, arity, and recursion &#8212; 3 concepts/features that Javascript [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: A Better Javascript Memoizer &#171; Internet Turnkey Websites</title>
		<link>http://unscriptable.com/index.php/2009/05/01/a-better-javascript-memoizer/comment-page-1/#comment-519</link>
		<dc:creator>A Better Javascript Memoizer &#171; Internet Turnkey Websites</dc:creator>
		<pubDate>Fri, 08 May 2009 02:21:08 +0000</pubDate>
		<guid isPermaLink="false">http://unscriptable.com/?p=272#comment-519</guid>
		<description>[...] have covered memoizers in the past, but John Hann has posted on a nice implementation that takes advantage of closures, arity, and recursion &#8212; 3 concepts/features that Javascript [...]</description>
		<content:encoded><![CDATA[<p>[...] have covered memoizers in the past, but John Hann has posted on a nice implementation that takes advantage of closures, arity, and recursion &#8212; 3 concepts/features that Javascript [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Naeem</title>
		<link>http://unscriptable.com/index.php/2009/05/01/a-better-javascript-memoizer/comment-page-1/#comment-518</link>
		<dc:creator>Naeem</dc:creator>
		<pubDate>Thu, 07 May 2009 20:19:32 +0000</pubDate>
		<guid isPermaLink="false">http://unscriptable.com/?p=272#comment-518</guid>
		<description>Good work John.</description>
		<content:encoded><![CDATA[<p>Good work John.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dave</title>
		<link>http://unscriptable.com/index.php/2009/05/01/a-better-javascript-memoizer/comment-page-1/#comment-517</link>
		<dc:creator>Dave</dc:creator>
		<pubDate>Wed, 06 May 2009 12:56:40 +0000</pubDate>
		<guid isPermaLink="false">http://unscriptable.com/?p=272#comment-517</guid>
		<description>Like that page says, probably the best thing to do for Object is to document that it doesn&#039;t work. You could write a version that serialized Object to string (recursively!) or heck, turn it into JSON and use that string. 

I just realized my untested code above has some mistakes...not surprising. Delete the line starting &quot;var created&quot; and change age.getSeconds()-maxage to expires.getSeconds()+maxage.</description>
		<content:encoded><![CDATA[<p>Like that page says, probably the best thing to do for Object is to document that it doesn&#8217;t work. You could write a version that serialized Object to string (recursively!) or heck, turn it into JSON and use that string. </p>
<p>I just realized my untested code above has some mistakes&#8230;not surprising. Delete the line starting &#8220;var created&#8221; and change age.getSeconds()-maxage to expires.getSeconds()+maxage.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Twitted by segdeha</title>
		<link>http://unscriptable.com/index.php/2009/05/01/a-better-javascript-memoizer/comment-page-1/#comment-515</link>
		<dc:creator>Twitted by segdeha</dc:creator>
		<pubDate>Wed, 06 May 2009 07:09:43 +0000</pubDate>
		<guid isPermaLink="false">http://unscriptable.com/?p=272#comment-515</guid>
		<description>[...] This post was Twitted by segdeha - Real-url.org [...]</description>
		<content:encoded><![CDATA[<p>[...] This post was Twitted by segdeha &#8211; Real-url.org [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John H</title>
		<link>http://unscriptable.com/index.php/2009/05/01/a-better-javascript-memoizer/comment-page-1/#comment-513</link>
		<dc:creator>John H</dc:creator>
		<pubDate>Wed, 06 May 2009 00:23:56 +0000</pubDate>
		<guid isPermaLink="false">http://unscriptable.com/?p=272#comment-513</guid>
		<description>Hey Dave, thanks for the code example!  

I originally decided to stay away from joining the serialized params because of the difficulty in choosing the join separator string.  Yours looks pretty darn safe, imho, but there is still a minute chance that there could be ambiguities (false positives) in the cache caused when the parameters contain the join separator string.  

My goal was to see if I could find a method that worked 100% of the time.  I didn&#039;t quite achieve my goal*, but I think that I got 0.00001% further because I eliminated the join ambiguities.

* Objects serialize to &quot;[Object object]&quot;. Doh!  See kangax&#039;s note on this memoization implementation: &lt;a href=&quot;http://blog.thejit.org/2008/09/05/memoization-in-javascript/&quot; rel=&quot;nofollow&quot;&gt;http://blog.thejit.org/2008/09/05/memoization-in-javascript/&lt;/a&gt;</description>
		<content:encoded><![CDATA[<p>Hey Dave, thanks for the code example!  </p>
<p>I originally decided to stay away from joining the serialized params because of the difficulty in choosing the join separator string.  Yours looks pretty darn safe, imho, but there is still a minute chance that there could be ambiguities (false positives) in the cache caused when the parameters contain the join separator string.  </p>
<p>My goal was to see if I could find a method that worked 100% of the time.  I didn&#8217;t quite achieve my goal*, but I think that I got 0.00001% further because I eliminated the join ambiguities.</p>
<p>* Objects serialize to &#8220;[Object object]&#8220;. Doh!  See kangax&#8217;s note on this memoization implementation: <a href="http://blog.thejit.org/2008/09/05/memoization-in-javascript/" rel="nofollow">http://blog.thejit.org/2008/09/05/memoization-in-javascript/</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John H</title>
		<link>http://unscriptable.com/index.php/2009/05/01/a-better-javascript-memoizer/comment-page-1/#comment-512</link>
		<dc:creator>John H</dc:creator>
		<pubDate>Wed, 06 May 2009 00:10:17 +0000</pubDate>
		<guid isPermaLink="false">http://unscriptable.com/?p=272#comment-512</guid>
		<description>Sure, Vijay.  Timeouts are easy.  Explicit cache invalidation is harder if you&#039;re trying not to use members on the function instance.  I think I&#039;ll set out to solve all three cases:
1) setTimeout-based invalidation
2) simple, unmemoize method member on function instance
3) unmemoize without touching the function instance

Thanks for the feedback!</description>
		<content:encoded><![CDATA[<p>Sure, Vijay.  Timeouts are easy.  Explicit cache invalidation is harder if you&#8217;re trying not to use members on the function instance.  I think I&#8217;ll set out to solve all three cases:<br />
1) setTimeout-based invalidation<br />
2) simple, unmemoize method member on function instance<br />
3) unmemoize without touching the function instance</p>
<p>Thanks for the feedback!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John H</title>
		<link>http://unscriptable.com/index.php/2009/05/01/a-better-javascript-memoizer/comment-page-1/#comment-511</link>
		<dc:creator>John H</dc:creator>
		<pubDate>Wed, 06 May 2009 00:04:16 +0000</pubDate>
		<guid isPermaLink="false">http://unscriptable.com/?p=272#comment-511</guid>
		<description>Thanks for your input, EllisGL!  Excellent point, too.  The usual trade-off: speed for memory.  

So, here&#039;s a question: should the unmemoize feature forget the cached results at a strict future time (exactly at the designated expiration) or should it only forget at the next convenient time (some time after expiration)?  

More specifically: 
&lt;pre&gt;setTimeout(unmemoize, expiryPeriod); // strict time&lt;/pre&gt;
or 
&lt;pre&gt;if(new Date() &gt; expiryDate) unmemoize(); // this is in the memoize method&lt;/pre&gt;

Using a setTimeout will enforce a strict expiry time (assuming that the UI thread is not too busy).  Otherwise, we can just check for expired cache entries when we&#039;re adding new ones.  This would allow us to prioritize as you mentioned.  However, it seems like a lot more code / effort / memory.  

Thoughts?</description>
		<content:encoded><![CDATA[<p>Thanks for your input, EllisGL!  Excellent point, too.  The usual trade-off: speed for memory.  </p>
<p>So, here&#8217;s a question: should the unmemoize feature forget the cached results at a strict future time (exactly at the designated expiration) or should it only forget at the next convenient time (some time after expiration)?  </p>
<p>More specifically: </p>
<pre>setTimeout(unmemoize, expiryPeriod); // strict time</pre>
<p>or </p>
<pre>if(new Date() &gt; expiryDate) unmemoize(); // this is in the memoize method</pre>
<p>Using a setTimeout will enforce a strict expiry time (assuming that the UI thread is not too busy).  Otherwise, we can just check for expired cache entries when we&#8217;re adding new ones.  This would allow us to prioritize as you mentioned.  However, it seems like a lot more code / effort / memory.  </p>
<p>Thoughts?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: A Better Javascript Memoizer</title>
		<link>http://unscriptable.com/index.php/2009/05/01/a-better-javascript-memoizer/comment-page-1/#comment-510</link>
		<dc:creator>A Better Javascript Memoizer</dc:creator>
		<pubDate>Tue, 05 May 2009 20:49:13 +0000</pubDate>
		<guid isPermaLink="false">http://unscriptable.com/?p=272#comment-510</guid>
		<description>[...] have covered memoizers in the past, but John Hann has posted on a nice implementation that takes advantage of closures, arity, and recursion &#8212; 3 concepts/features that Javascript [...]</description>
		<content:encoded><![CDATA[<p>[...] have covered memoizers in the past, but John Hann has posted on a nice implementation that takes advantage of closures, arity, and recursion &#8212; 3 concepts/features that Javascript [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dave</title>
		<link>http://unscriptable.com/index.php/2009/05/01/a-better-javascript-memoizer/comment-page-1/#comment-508</link>
		<dc:creator>Dave</dc:creator>
		<pubDate>Tue, 05 May 2009 13:31:51 +0000</pubDate>
		<guid isPermaLink="false">http://unscriptable.com/?p=272#comment-508</guid>
		<description>If all the args have to be serializable to string, why not do them all at once? As long as you pick a delimiter unlikely to be in the arguments there&#039;s no ambiguity. Here&#039;s what I mean, untested:

&lt;pre lang=&quot;javacscript&quot;&gt;
function memoize (func, context, maxage) {
  var cache = {}, expiration = {};
  maxage = maxage &#124;&#124; 24*60*60;	// default 24 hours
  return function () {
    var signature = Array.join.apply(arguments, &quot;\x01&quot;);
    var created = new Date(); age.setSeconds(age.getSeconds()-maxage);
    if ( !(signature in cache) &#124;&#124; expiration[signature] &lt; (new Date) ) {
      cache[signature] = func.apply(context, arguments);
      var expires = new Date(); expires.setSeconds(age.getSeconds()-maxage);
      expiration[signature] = expires;
    }
    return cache[signature];
  }
}
&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>If all the args have to be serializable to string, why not do them all at once? As long as you pick a delimiter unlikely to be in the arguments there&#8217;s no ambiguity. Here&#8217;s what I mean, untested:</p>

<div class="wp_syntax"><div class="code"><pre class="javacscript" style="font-family:monospace;">function memoize (func, context, maxage) {
  var cache = {}, expiration = {};
  maxage = maxage || 24*60*60;	// default 24 hours
  return function () {
    var signature = Array.join.apply(arguments, &quot;\x01&quot;);
    var created = new Date(); age.setSeconds(age.getSeconds()-maxage);
    if ( !(signature in cache) || expiration[signature] &amp;lt; (new Date) ) {
      cache[signature] = func.apply(context, arguments);
      var expires = new Date(); expires.setSeconds(age.getSeconds()-maxage);
      expiration[signature] = expires;
    }
    return cache[signature];
  }
}</pre></div></div>

]]></content:encoded>
	</item>
</channel>
</rss>
