Dependencies: excluding a constant from reloading

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