# Does anybody out there know rails internals?

**URL:** <https://www.ruby-forum.com/t/does-anybody-out-there-know-rails-internals/118184>\
**Category:** Rails\
**Created:** [October 24, 2007, 4:28pm UTC](https://www.ruby-forum.com/t/does-anybody-out-there-know-rails-internals/118184 "2007-10-24T16:28:59Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![gonesail](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/35a633/32.png) [@gonesail](https://www.ruby-forum.com/u/gonesail)\
**Post date:** [October 24, 2007, 4:28pm UTC](https://www.ruby-forum.com/t/does-anybody-out-there-know-rails-internals/118184/1 "2007-10-24T16:28:59Z")

</div>

i need to call a sweeper directly from a model to expire cache (the  
sweeper is observing the model as usual). why is this not documented?  
seems like something that everybody would need to know!!

---

<div class="post-metadata">

**Author:** ![gonesail](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/35a633/32.png) [@gonesail](https://www.ruby-forum.com/u/gonesail)\
**Post date:** [October 24, 2007, 6:46pm UTC](https://www.ruby-forum.com/t/does-anybody-out-there-know-rails-internals/118184/2 "2007-10-24T18:46:25Z")

</div>

come on people. this should be simple to do. the sweeper is observing  
the model … how do I call the sweeper.after\_save(record) method from  
the model?

---

<div class="post-metadata">

**Author:** ![gonesail](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/35a633/32.png) [@gonesail](https://www.ruby-forum.com/u/gonesail)\
**Post date:** [October 24, 2007, 8:09pm UTC](https://www.ruby-forum.com/t/does-anybody-out-there-know-rails-internals/118184/3 "2007-10-24T20:09:49Z")

</div>

OK another approach: initialize a new sweeper and call from model.  
another gotcha the new method is private for  
ActionController::Caching::Sweeper. can anybody help with this?  
there’s no documentation.

---

<div class="post-metadata">

**Author:** ![gonesail](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/35a633/32.png) [@gonesail](https://www.ruby-forum.com/u/gonesail)\
**Post date:** [October 24, 2007, 9:41pm UTC](https://www.ruby-forum.com/t/does-anybody-out-there-know-rails-internals/118184/4 "2007-10-24T21:41:02Z")

</div>

On 10/24/07, Gone S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> OK another approach: initialize a new sweeper and call from model.  
> another gotcha the new method is private for  
> ActionController::Caching::Sweeper. can anybody help with this?  
> there’s no documentation.

I haven’t used sweepers, so I’m not much help; but it looks like this  
is a singleton. So you would need SomeSweeper.instance to get at the  
singleton object. Not sure what you would do with it though…

---

<div class="post-metadata">

**Author:** ![gonesail](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/35a633/32.png) [@gonesail](https://www.ruby-forum.com/u/gonesail)\
**Post date:** [October 24, 2007, 10:01pm UTC](https://www.ruby-forum.com/t/does-anybody-out-there-know-rails-internals/118184/5 "2007-10-24T22:01:53Z")

</div>

i did it!! from within the model call sweeper.instance.after\_save(parm)  
and you have expired the cache (assume after\_save is the name of the  
sweeper class method that is observing the model). you’re right it is a  
singleton … thanks.

---

<div class="post-metadata">

**Author:** ![gonesail](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/35a633/32.png) [@gonesail](https://www.ruby-forum.com/u/gonesail)\
**Post date:** [October 24, 2007, 9:49pm UTC](https://www.ruby-forum.com/t/does-anybody-out-there-know-rails-internals/118184/6 "2007-10-24T21:49:49Z")

</div>

On 10/24/07, Bob S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> singleton object. Not sure what you would do with it though…  
> Sweepers are half AR Observer and half controller filter. This means  
> they have to run from a controller. That’s where the methods for  
> expiring stuff lives. You’re probably better off using an Observer  
> then.

–  
Rick O.  
[http://lighthouseapp.com](http://lighthouseapp.com)  
[http://weblog.techno-weenie.net](http://weblog.techno-weenie.net)  
[http://mephistoblog.com](http://mephistoblog.com)
