<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Involution &#187; Memcached</title>
	<atom:link href="http://involution.com/category/memcached/feed/" rel="self" type="application/rss+xml" />
	<link>http://involution.com</link>
	<description>Tony Perrie&#039;s Weblog</description>
	<lastBuildDate>Fri, 19 Aug 2011 19:46:41 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Interactive Memcached Debugging with Rails</title>
		<link>http://involution.com/2009/06/20/interactive-memcached-debugging-with-rails/</link>
		<comments>http://involution.com/2009/06/20/interactive-memcached-debugging-with-rails/#comments</comments>
		<pubDate>Sat, 20 Jun 2009 23:17:37 +0000</pubDate>
		<dc:creator>Tony Perrie</dc:creator>
				<category><![CDATA[Memcached]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://involution.com/?p=1238</guid>
		<description><![CDATA[The memcached support in Rails is great, but it&#8217;s a bit difficult to see what the heck is going on in a production environment. The first problem is, by default Rails doesn&#8217;t keep a list of all memcached keys that are available on the system. So, you have to use a plugin like memcache_store_with_delete_matched to [...]]]></description>
			<content:encoded><![CDATA[<p>The memcached support in Rails is great, but it&#8217;s a bit difficult to see what the heck is going on in a production environment.  The first problem is, by default Rails doesn&#8217;t keep a list of all memcached keys that are available on the system.  So, you have to use a plugin like <a href="http://github.com/lacomartincik/memcache_store_with_delete_matched/tree/master">memcache_store_with_delete_matched</a> to have memcache itself store a list of all available keys.  </p>
<p>You can install this plugin with the typical <code>script/plugin</code> command. </p>
<pre><code>script/plugin install git://github.com/lacomartincik/memcache-store-with-delete_matched.git
</code></pre>
<p>Then, you configure memcached in your <code>environment.rb</code> like this. </p>
<pre><code>mem_cache_options = {
    :c_threshold => 10000,
    :compression => true,
    :debug => false,
    :timeout => false,
    :namespace => 'app',
    :readonly => false,
    :urlencode => false
  }
  config.action_controller.cache_store = <b>:mem_cache_store_with_delete_matched</b>, ['127.0.0.1:11211'], mem_cache_options
</code></pre>
<p>The other benefit to using memcache_store_with_delete_matched is that regular expressions within <code>expire_fragment</code> works. </p>
<pre><code>expire_fragment(%r!/index_user_.*!)
</code></pre>
<p>So, down to debugging.  If you want to see all keys in a <code>script/console</code>, you can do the following. </p>
<pre><code>YAML.load(ActionController::Base.cache_store.fetch("memcached_store_key_list"))
</code></pre>
<p>You can select certain keys from the memcached_store_keylist. </p>
<pre><code>YAML.load(ActionController::Base.cache_store.fetch("memcached_store_key_list")) .detect{ |k| k.match(/index/) }
</code></pre>
<p>Once you have the list of keys, you can plug them into a fetch command. </p>
<pre><code>ActionController::Base.cache_store.fetch("app/blog/index")
</code></pre>
<p>You can also manually expire keys from a console. </p>
<pre><code>c = ApplicationController.new
c.expire_fragment(/index/)
</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://involution.com/2009/06/20/interactive-memcached-debugging-with-rails/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

