<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>An Async Html cache – Part I - Writing the cache</title><link>http://blogs.msdn.com/b/lucabol/archive/2009/04/27/an-async-html-cache-part-i.aspx</link><description>Other posts: 
 
 Part II - Testing the cache 
 In the process of converting a financial VBA Excel Addin to .NET (more on that in later posts), I found myself in dire need of a HTML cache that can be called from multiple threads without blocking them</description><dc:language>en-US</dc:language><generator>Telligent Evolution Platform Developer Build (Build: 5.6.50428.7875)</generator><item><title>An Async Html cache – part II – Testing the cache</title><link>http://blogs.msdn.com/b/lucabol/archive/2009/04/27/an-async-html-cache-part-i.aspx#9597210</link><pubDate>Fri, 08 May 2009 18:53:22 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9597210</guid><dc:creator>Luca Bolognese's WebLog</dc:creator><description>&lt;p&gt;Other posts: Part I – Writing the cache Let’s try out our little cache. First I want to write a synchronous&lt;/p&gt;
&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9597210" width="1" height="1"&gt;</description></item><item><title>Luca Bolognese on HTML caching in VB.NET (Lisa Feigenbaum)</title><link>http://blogs.msdn.com/b/lucabol/archive/2009/04/27/an-async-html-cache-part-i.aspx#9576319</link><pubDate>Wed, 29 Apr 2009 22:15:28 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9576319</guid><dc:creator>The Visual Basic Team</dc:creator><description>&lt;p&gt;You may know Luca Bolognese from his well-known work on C# LINQ. Luca is now the Group Program Manager&lt;/p&gt;
&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9576319" width="1" height="1"&gt;</description></item><item><title>async</title><link>http://blogs.msdn.com/b/lucabol/archive/2009/04/27/an-async-html-cache-part-i.aspx#9576315</link><pubDate>Wed, 29 Apr 2009 22:11:51 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9576315</guid><dc:creator>Greg</dc:creator><description>&lt;p&gt;The idea of wrapping the asychronous cache handler in a class is to reduce or eliminate the need for callers to bbe asychronous. &amp;nbsp;This makes coding the caller's class much easier.&lt;/p&gt;
&lt;p&gt;The other aspect is that the amount of work done in an asychronous call back should be minimal since you don't know when it will be executed. &amp;nbsp;For example, you get a callback call with the HTML you need whilst you are destroying the caller's object. &amp;nbsp;This is more important when dealing with large amounts of data in each cach entry (e.g., large xml strings) since processing each cache entry may take considerable time.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9576315" width="1" height="1"&gt;</description></item><item><title>re: An Async Html cache – part I</title><link>http://blogs.msdn.com/b/lucabol/archive/2009/04/27/an-async-html-cache-part-i.aspx#9576134</link><pubDate>Wed, 29 Apr 2009 20:39:11 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9576134</guid><dc:creator>lucabol</dc:creator><description>&lt;p&gt;Thanks Greg, these are good comments.&lt;/p&gt;
&lt;p&gt;We have a different design goal though. Both solutions are valid. I want the method requesting the URL to have the flexibility of deciding what to do (aka have a callback). I do want the exposed API to be async.&lt;/p&gt;
&lt;p&gt;The rest of your comments talk to the difference between writing production code and a conceptual example. I'm doing the latter here.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9576134" width="1" height="1"&gt;</description></item><item><title>Simpler method</title><link>http://blogs.msdn.com/b/lucabol/archive/2009/04/27/an-async-html-cache-part-i.aspx#9576108</link><pubDate>Wed, 29 Apr 2009 20:20:09 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9576108</guid><dc:creator>Greg</dc:creator><description>&lt;p&gt;It would be much easier to use a normal thread safe collection class.&lt;/p&gt;
&lt;p&gt;Each element would have:&lt;/p&gt;
&lt;p&gt; &amp;nbsp;key&lt;/p&gt;
&lt;p&gt; &amp;nbsp;url (string)&lt;/p&gt;
&lt;p&gt; &amp;nbsp;status (loaded, failed, waiting to load, partially loaded)&lt;/p&gt;
&lt;p&gt; &amp;nbsp;last status change (date/time)&lt;/p&gt;
&lt;p&gt; &amp;nbsp;html_loaded (string)&lt;/p&gt;
&lt;p&gt; &amp;nbsp;last_referenced (date/time)&lt;/p&gt;
&lt;p&gt; &amp;nbsp;can_timeout_and_be_deleted(boolean)&lt;/p&gt;
&lt;p&gt;Class methods&lt;/p&gt;
&lt;p&gt; &amp;nbsp; Get HTML from URL(boolean lookup_only = false, int max_block_seconds = 0 /* -1 block forever, 0 - don't block, otherwise block for X seconds*/)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; Get HTML from KEY(boolean lookup_only = false)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; Delete_entry(URL)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; Delete_entry(KEY)&lt;/p&gt;
&lt;p&gt;A thread or threads internal to the class would load the html asychronously and be invoked via a clock timer with ticks a few seconds apart.&lt;/p&gt;
&lt;p&gt;Attaching a callback for each request is much harder to implement. &amp;nbsp;It is upto the method requesting the URL to decide whether or not it blocks, needs an asychronous callback/interrupt or polls for data. &amp;nbsp;&lt;/p&gt;
&lt;p&gt;The idea is that for nearly all cases, no new threads should be created and no new callbacks should be hooked up. &amp;nbsp;This keeps your code easier to understand and debug. &amp;nbsp;Common faults and scenarios are handled easily:&lt;/p&gt;
&lt;p&gt; &amp;nbsp;- requesting thread terminates&lt;/p&gt;
&lt;p&gt; &amp;nbsp;- asynchronous load times out&lt;/p&gt;
&lt;p&gt; &amp;nbsp;- error loading html&lt;/p&gt;
&lt;p&gt; &amp;nbsp;- html hasn't been used for 5 minutes and can be removed (a tunable cache parameter)&lt;/p&gt;
&lt;p&gt; &amp;nbsp;- memory limit of cache reached and unreferenced html strings can be removed (a tunable cache parameter)&lt;/p&gt;
&lt;p&gt; &amp;nbsp;- duplicate request for a URL/KEY from more than one thread&lt;/p&gt;
&lt;p&gt; &amp;nbsp;- html can be loaded from multiple sources (web, file, network share, ftp, database, etc.).&lt;/p&gt;
&lt;p&gt; &amp;nbsp;- html load failed as html string exceeds the size limit on loaded string (e.g., a tunable cache parameter)&lt;/p&gt;
&lt;p&gt; &amp;nbsp;- The common problem with attempting a callback for a method that is terminated is avoided. &amp;nbsp;That's a problem when the callback requires the cache to build a complex packet of data to pass in the callback.&lt;/p&gt;
&lt;p&gt;This is quite similar to basic page handling algorithm in a virtual memory system (circa 1980). &amp;nbsp;It's how one handled this in systems lacking real threading or with non-reentrant GUI message handling (VB6 GUI/MFC GUI posting a message to the current winform indiciating asynchronous request completed).&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9576108" width="1" height="1"&gt;</description></item><item><title>An Async Html cache ??? part I | ASP NET Hosting</title><link>http://blogs.msdn.com/b/lucabol/archive/2009/04/27/an-async-html-cache-part-i.aspx#9572540</link><pubDate>Tue, 28 Apr 2009 03:27:49 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9572540</guid><dc:creator>An Async Html cache ??? part I | ASP NET Hosting</dc:creator><description>&lt;p&gt;PingBack from &lt;a rel="nofollow" target="_new" href="http://asp-net-hosting.simplynetdev.com/an-async-html-cache-%e2%80%93-part-i/"&gt;http://asp-net-hosting.simplynetdev.com/an-async-html-cache-%e2%80%93-part-i/&lt;/a&gt;&lt;/p&gt;
&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9572540" width="1" height="1"&gt;</description></item></channel></rss>