<?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: Easily cache results from Javascript functions</title>
	<atom:link href="http://www.gunnarsteinn.com/2009/09/easily-cache-results-from-javascript-functions/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.gunnarsteinn.com/2009/09/easily-cache-results-from-javascript-functions/</link>
	<description></description>
	<lastBuildDate>Wed, 23 Sep 2009 22:48:27 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=abc</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Gunnar Steinn</title>
		<link>http://www.gunnarsteinn.com/2009/09/easily-cache-results-from-javascript-functions/comment-page-1/#comment-7501</link>
		<dc:creator>Gunnar Steinn</dc:creator>
		<pubDate>Wed, 23 Sep 2009 22:48:27 +0000</pubDate>
		<guid isPermaLink="false">http://www.gunnarsteinn.com/?p=1147#comment-7501</guid>
		<description>&lt;a href=&quot;#comment-7500&quot; rel=&quot;nofollow&quot;&gt;@jetm &lt;/a&gt; 
Thanks, fixed the link</description>
		<content:encoded><![CDATA[<p><a href="#comment-7500" rel="nofollow">@jetm </a><br />
Thanks, fixed the link</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jetm</title>
		<link>http://www.gunnarsteinn.com/2009/09/easily-cache-results-from-javascript-functions/comment-page-1/#comment-7500</link>
		<dc:creator>jetm</dc:creator>
		<pubDate>Wed, 23 Sep 2009 17:54:30 +0000</pubDate>
		<guid isPermaLink="false">http://www.gunnarsteinn.com/?p=1147#comment-7500</guid>
		<description>URL: 
http://www.gunnarsteinn.com/2009/09/easily-cache-results-from-javascript-functions/wp-content/cache.html

Is don&#039;t working</description>
		<content:encoded><![CDATA[<p>URL:<br />
<a href="http://www.gunnarsteinn.com/2009/09/easily-cache-results-from-javascript-functions/wp-content/cache.html" rel="nofollow">http://www.gunnarsteinn.com/2009/09/easily-cache-results-from-javascript-functions/wp-content/cache.html</a></p>
<p>Is don&#8217;t working</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gunnar Steinn</title>
		<link>http://www.gunnarsteinn.com/2009/09/easily-cache-results-from-javascript-functions/comment-page-1/#comment-7497</link>
		<dc:creator>Gunnar Steinn</dc:creator>
		<pubDate>Mon, 21 Sep 2009 17:03:09 +0000</pubDate>
		<guid isPermaLink="false">http://www.gunnarsteinn.com/?p=1147#comment-7497</guid>
		<description>Adrians approach works well except that arguments isn&#039;t a proper Array in Javascript so you will have to use the &quot;Array.slice.call(arguments).join(&#039;&#124;&#039;)&quot; line from my code.</description>
		<content:encoded><![CDATA[<p>Adrians approach works well except that arguments isn&#8217;t a proper Array in Javascript so you will have to use the &#8220;Array.slice.call(arguments).join(&#8217;|')&#8221; line from my code.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bob</title>
		<link>http://www.gunnarsteinn.com/2009/09/easily-cache-results-from-javascript-functions/comment-page-1/#comment-7496</link>
		<dc:creator>Bob</dc:creator>
		<pubDate>Mon, 21 Sep 2009 16:44:19 +0000</pubDate>
		<guid isPermaLink="false">http://www.gunnarsteinn.com/?p=1147#comment-7496</guid>
		<description>I came up with an alternative version as well, looks like Adrian beat me to it.

My commentary is here:

http://www.reddit.com/r/programming/comments/9mm5o/easily_cache_results_from_javascript_functions/c0deuu8

I put Adrian&#039;s thing in there, to get the formatting back. Woo!</description>
		<content:encoded><![CDATA[<p>I came up with an alternative version as well, looks like Adrian beat me to it.</p>
<p>My commentary is here:</p>
<p><a href="http://www.reddit.com/r/programming/comments/9mm5o/easily_cache_results_from_javascript_functions/c0deuu8" rel="nofollow">http://www.reddit.com/r/programming/comments/9mm5o/easily_cache_results_from_javascript_functions/c0deuu8</a></p>
<p>I put Adrian&#8217;s thing in there, to get the formatting back. Woo!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Adrian Quark</title>
		<link>http://www.gunnarsteinn.com/2009/09/easily-cache-results-from-javascript-functions/comment-page-1/#comment-7495</link>
		<dc:creator>Adrian Quark</dc:creator>
		<pubDate>Mon, 21 Sep 2009 15:46:17 +0000</pubDate>
		<guid isPermaLink="false">http://www.gunnarsteinn.com/?p=1147#comment-7495</guid>
		<description>Sorry about the formatting, the blog software seems to lose indentation even though I used a &lt;code/&gt; block.

&lt;em&gt;[EDIT: Fixed :) Gunnar Steinn]&lt;/em&gt;</description>
		<content:encoded><![CDATA[<p>Sorry about the formatting, the blog software seems to lose indentation even though I used a &lt;code/&gt; block.</p>
<p><em>[EDIT: Fixed <img src='http://www.gunnarsteinn.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  Gunnar Steinn]</em></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Adrian Quark</title>
		<link>http://www.gunnarsteinn.com/2009/09/easily-cache-results-from-javascript-functions/comment-page-1/#comment-7494</link>
		<dc:creator>Adrian Quark</dc:creator>
		<pubDate>Mon, 21 Sep 2009 15:45:15 +0000</pubDate>
		<guid isPermaLink="false">http://www.gunnarsteinn.com/?p=1147#comment-7494</guid>
		<description>A few problems with this:
1. the .name property is a much easier way to get the name of a function.
2. this won&#039;t work with anonymous functions.
3. because it uses a global cache the cached values won&#039;t be garbage collected even if the function goes away (e.g. it&#039;s an event handler).
4. if your function takes a variable number of arguments and one contains a &quot;&#124;&quot; the cache won&#039;t work correctly.
5. if the function returns null this won&#039;t be cached
6. the cache key won&#039;t work with Object values since they don&#039;t have a unique string representation. You need to use something like http://www.timdown.co.uk/jshashtable/ to get around that.

You can fix 1-5 with some minor modifications:

[js  entities=&#039;1&#039;]
function memoise(f) {
  var cache = {};
  return function () {
    var key = arguments.length+&quot;&#124;&quot;+arguments.join(&quot;&#124;&quot;);
    if (cache[key] === undefined) {
      cache[key] = f.apply(this, arguments);
    }
    return cache[key];
  }
}

isPrime = memoise(isPrime);
[/js]</description>
		<content:encoded><![CDATA[<p>A few problems with this:<br />
1. the .name property is a much easier way to get the name of a function.<br />
2. this won&#8217;t work with anonymous functions.<br />
3. because it uses a global cache the cached values won&#8217;t be garbage collected even if the function goes away (e.g. it&#8217;s an event handler).<br />
4. if your function takes a variable number of arguments and one contains a &#8220;|&#8221; the cache won&#8217;t work correctly.<br />
5. if the function returns null this won&#8217;t be cached<br />
6. the cache key won&#8217;t work with Object values since they don&#8217;t have a unique string representation. You need to use something like <a href="http://www.timdown.co.uk/jshashtable/" rel="nofollow">http://www.timdown.co.uk/jshashtable/</a> to get around that.</p>
<p>You can fix 1-5 with some minor modifications:</p>
<pre class="brush: jscript;">
function memoise(f) {
  var cache = {};
  return function () {
    var key = arguments.length+&quot;|&quot;+arguments.join(&quot;|&quot;);
    if (cache[key] === undefined) {
      cache[key] = f.apply(this, arguments);
    }
    return cache[key];
  }
}

isPrime = memoise(isPrime);
</pre>
]]></content:encoded>
	</item>
</channel>
</rss>
