<?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>Prateek Dayal &#187; cache_sweeper</title>
	<atom:link href="http://www.prateekdayal.net/category/cache_sweeper/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.prateekdayal.net</link>
	<description>Ruby on Rails + Web 2.0 + Life :)</description>
	<lastBuildDate>Fri, 20 May 2011 16:13:31 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Rails : Accessing session data in models</title>
		<link>http://www.prateekdayal.net/2007/10/25/rails-accessing-session-data-in-models/</link>
		<comments>http://www.prateekdayal.net/2007/10/25/rails-accessing-session-data-in-models/#comments</comments>
		<pubDate>Thu, 25 Oct 2007 11:30:01 +0000</pubDate>
		<dc:creator>Prateek Dayal</dc:creator>
				<category><![CDATA[activerecord]]></category>
		<category><![CDATA[cache_sweeper]]></category>
		<category><![CDATA[rubyonrails]]></category>

		<guid isPermaLink="false">http://prateekdayal.net/blog/2007/10/25/rails-accessing-session-data-in-models/</guid>
		<description><![CDATA[MVC architecture is good for keeping your design neat but once in a while you hit a road block and this is one such situtation. If you want to log actions/events in your code and track changes to models, you would want to do that in the activerecord callback hooks like after_save and before_destroy. However [...]]]></description>
			<content:encoded><![CDATA[<p>MVC architecture is good for keeping your design neat but once in a while you hit a road block and this is one such situtation.  If you want to log actions/events in your code and track changes to models, you would want to do that in the activerecord callback hooks like after_save and before_destroy. However these methods have only access to the record that is  affected and not to the session data. Therefore, you cannot log &#8216;who&#8217; made the change.</p>
<p>After some googling around and wasting an hour or so, I found out that the trick is to use cache_sweeper class, which keeps a track of the objects that you ask it to for regenerating caches. You can however use it to keep a track of your changes and log it. Cache Sweeper objects also have access to the session data so you can know &#8216;who&#8217; made changes to your model.</p>
<p><!--adsense--></p>
<p>The process is described further in Rails Recipes book and is quite interesting &#8230; go read on :)</p>
<script type="text/javascript">
  addthis_url    = 'http%3A%2F%2Fwww.prateekdayal.net%2F2007%2F10%2F25%2Frails-accessing-session-data-in-models%2F';
  addthis_title  = 'Rails+%3A+Accessing+session+data+in+models';
  addthis_pub    = 'prateek';
</script><script type="text/javascript" src="http://s7.addthis.com/js/addthis_widget.php?v=12" ></script>
]]></content:encoded>
			<wfw:commentRss>http://www.prateekdayal.net/2007/10/25/rails-accessing-session-data-in-models/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

