<?xml version="1.0" encoding="iso-8859-1"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>dekstop weblog : SQLite3FeedCache: A Custom Thread-Safe Database Cache for FeedTools</title>
    <link>http://dekstop.de/weblog/2006/03/custom_sqlite3_feed_cache_for_feedtools/</link>
    <description> I just finished a first version of a custom database cache for FeedTools 0.2.23 -- basically a drop-in replacement for the default DatabaseFeedCache. I did this for two reasons: first, because I could (always a good reason), and second, because DatabaseFeedCache does not work at all in multi-threaded applications. ...</description>
    <dc:language>en-us</dc:language>
    <dc:rights>Copyright 2006 Martin Dittus</dc:rights>
    <lastBuildDate>Tue, 07 Mar 2006 21:21:25 GMT</lastBuildDate>
    <generator>MicroLinks 5.6 (dekstop.de)</generator>
    <managingEditor>public&#64;dekstop&#46;de</managingEditor>
    <webMaster>public&#64;dekstop&#46;de</webMaster>

    <item>
      <title>Comment on "SQLite3FeedCache: A Custom Thread-Safe Database Cache for FeedTools"</title>
      <link>http://dekstop.de/weblog/2006/03/custom_sqlite3_feed_cache_for_feedtools/#168</link>
      <description><![CDATA[<p>Unlikely in this state. Besides, it's of no value for people using other database engines -- someone would neet to port it to other SQL dialects.</p>

<p>But glad you like it! Let me know if you have ideas for improvement.</p>]]> &lt;p&gt;- <![CDATA[<a href="http://dekstop.de/" rel="nofollow">Martin Dittus</a>]]>&lt;/p&gt;</description>
      <dc:creator>Martin Dittus</dc:creator>
      <guid isPermaLink="true">http://dekstop.de/weblog/2006/03/custom_sqlite3_feed_cache_for_feedtools/#168</guid>
      <pubDate>Tue, 28 Mar 2006 23:39:42 GMT</pubDate>
    </item>
    <item>
      <title>Comment on "SQLite3FeedCache: A Custom Thread-Safe Database Cache for FeedTools"</title>
      <link>http://dekstop.de/weblog/2006/03/custom_sqlite3_feed_cache_for_feedtools/#167</link>
      <description><![CDATA[<p>Nice job, thanks!</p>

<p>Maybe this code should be included in FeedTools?</p>]]> &lt;p&gt;- <![CDATA[<a href="http://noboru.is.dreaming.org" rel="nofollow">Evgeny V. Oleynik</a>]]>&lt;/p&gt;</description>
      <dc:creator>Evgeny V. Oleynik</dc:creator>
      <guid isPermaLink="true">http://dekstop.de/weblog/2006/03/custom_sqlite3_feed_cache_for_feedtools/#167</guid>
      <pubDate>Tue, 28 Mar 2006 23:33:32 GMT</pubDate>
    </item>


    <item>
      <title>SQLite3FeedCache: A Custom Thread-Safe Database Cache for FeedTools</title>
      <link>http://dekstop.de/weblog/2006/03/custom_sqlite3_feed_cache_for_feedtools/</link> 
      <description><![CDATA[<table class="imagetable" border="0" width="500">
<tr>
	<td align="left">
		<img alt="textmate_output.png" src="http://dekstop.de/weblog/2006/03/custom_sqlite3_feed_cache_for_feedtools/textmate_output.png" width="450" height="319" border="0" /></td>
</tr>
</table>

<p>I just finished a first version of a custom database cache for <a href="http://sporkmonger.com/projects/feedtools/">FeedTools</a> 0.2.23 -- basically a drop-in replacement for the default DatabaseFeedCache. I did this for two reasons: first, because I could (always a good reason), and second, because DatabaseFeedCache does not work at all in multi-threaded applications. DatabaseFeedCache is based on ActiveRecord, and while ActiveRecord is supposed to be thread-safe since version 0.9 I've found this not no be true, at least when using SQLite3.</p>

<p>The implementation of SQLite3FeedCache is as basic as it gets, to the point where it's rather inefficient -- it does not even keep a persistent database connection, but reconnects and disconnects with every call to <tt>save</tt>, <tt>find_by_id</tt> and <tt>find_by_href</tt>.</p>

<p>But hey, it's thread-safe. ;)</p>

<p>You can browse the short <a href="http://dekstop.de/weblog/2006/03/custom_sqlite3_feed_cache_for_feedtools/doc/">SQLite3FeedCache documentation</a> for more details.</p>


<h3>Setup</h3>

<p>SQLite3FeedCache, like the original DatabaseFeedCache, requires you to set up a database cache file yourself before you can start using it. But that's easily done:</p>

<pre>
$ sqlite3 db/feeds.db &lt; db/schema.sqlite.sql 
</pre>

<p>If you look at the schema definition you'll see that it matches that of FeedTools -- which means you can use the same database cache with SQLite3FeedCache <em>and</em> FeedTools' default caching mechanism, as long as you're using SQLite 3.</p>


<h3>Example</h3>

<p>After setting up your database cache you can start using SQLite3FeedCache in your FeedTools script. Start your scripts like this:</p>

<pre>
# point SQLite3FeedCache to the database file
SQLite3FeedCache.set_db('db/feeds.db')
# tell FeedTools to use the SQLite3FeedCache
FeedTools::configurations[:feed_cache] = SQLite3FeedCache
</pre>

<p>... and that's all it takes. You now can start requesting and parsing feeds using the convenient FeedTools interface, and all requests will be cached by SQLite3FeedCache. See my earlier article, <a href="http://dekstop.de/weblog/2005/12/feedtools_cache_in_ruby_scripts/">Using the FeedTools Cache in Plain Ruby Scripts</a>, for some examples of how to request feeds with FeedTools.</p>

<p>Of course the main reason for using SQLite3FeedCache is its thread-safe implementation -- just be patient, I'll probably write a little about multi-threaded feed aggregation later.</p>


<h3>Disclaimer</h3>

<p>This is very new, and there might be bugs. My main goal for this initial version was to make it work at all.</p>

<p>And it's probably safe to say that this will break with the upcoming FeedTools 0.3 release.</p>

<p>Let me know how it works for you -- or even better, make suggestions for improvement.</p>

<p><strong>Update:</strong> I just uploaded a new version that fixes a small bug where feeds behind HTTP redirects were re-requested when they shouldn't be.</p>


<h3>Download</h3>

<ul class="links">
  <li><a href="http://dekstop.de/weblog/2006/03/custom_sqlite3_feed_cache_for_feedtools/sqlite3_feed_cache.rb">sqlite3_feed_cache.rb.txt</a>
  <li><a href="http://dekstop.de/weblog/2006/03/custom_sqlite3_feed_cache_for_feedtools/schema.sqlite.sql">schema.sqlite.sql</a> (database schema)</li>
</ul>]]></description>
      <dc:creator>Martin Dittus</dc:creator>
      <category>code</category>
      
      <guid isPermaLink="true">http://dekstop.de/weblog/2006/03/custom_sqlite3_feed_cache_for_feedtools/</guid>
      <pubDate>Tue, 07 Mar 2006 21:21:25 GMT</pubDate>
    </item>
  </channel>
</rss>
