# Dependencies: excluding a constant from reloading

**URL:** <https://www.ruby-forum.com/t/dependencies-excluding-a-constant-from-reloading/125916>\
**Category:** Rails\
**Created:** [January 13, 2008, 7:12pm UTC](https://www.ruby-forum.com/t/dependencies-excluding-a-constant-from-reloading/125916 "2008-01-13T19:12:47Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![wickie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/ba9def/32.png) [@wickie](https://www.ruby-forum.com/u/wickie)\
**Post date:** [January 13, 2008, 7:12pm UTC](https://www.ruby-forum.com/t/dependencies-excluding-a-constant-from-reloading/125916/1 "2008-01-13T19:12:47Z")

</div>

The Rails dependency mechanism tracks which constants are defined when  
anything is loaded automatically. In the development environment, these  
constants are undefined after each request, so that possibly changed  
versions can be reloaded for the next request.

Usually, that’s nice and everything, but my current case it leads to  
problems. I’m dynamically defining cache sweeper classes from within  
a “macro” in my controllers. These cache sweeper classes are bound to  
constants and as such are unloaded after the request. However, cache  
sweepers are also registered as observers on the relevant models and  
these registrations are retained across requests. Here’s where the  
trouble starts: observers are instantiated before the controller for  
the current request is loaded. As a result, on the second request, the  
Rails dispatcher tries to instantiate observers, the sweepers, that  
have been undefined at the end of the previous request, but not yet  
been re-defined on the current request.

Summing up, I need a clean way of telling the dependency mechanism not  
to unload my sweepers. From looking at the relevant code, I can  
probably wedge it in there with brute force, but that’s not what I’d  
like to do. Maybe I’ve just overlooked some elegant way to achieve what  
I want.

Michael

–  
Michael S.  
[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
[http://www.schuerig.de/michael/](http://www.schuerig.de/michael/)
