Can Rails cache a Controller "as long as code not changed"?

At work, we have a situation where when

  script/server

is run, then all the controller code is cached. This is to speed up the
development server. But that will mean that whenever we change the
controller code, we need to restart the server.

So we can turn off the caching of controller code all together. But
can't there be mechanism that is similar to the inclusion of javascript

  foo.js?1273424325

which is to use the cached version as long as there is no code change,
but recompile it when there is code change?

Maybe because we use HAML and SASS a lot, loading some page (such as the
homepage of the site) can take 40 seconds on the dev environment and it
is quite long.

Jian Lin wrote:

At work, we have a situation where when

  script/server

is run, then all the controller code is cached. This is to speed up the
development server. But that will mean that whenever we change the
controller code, we need to restart the server.

Yes, that's normal behavior in development mode.

So we can turn off the caching of controller code all together. But
can't there be mechanism that is similar to the inclusion of javascript

  foo.js?1273424325

which is to use the cached version as long as there is no code change,
but recompile it when there is code change?

Because it's a different kind of caching. JavaScript caching simply
involves using the browser cache for included files, whereas controller
caching involves Ruby objects in memory on the server.

Maybe because we use HAML and SASS a lot, loading some page (such as the
homepage of the site) can take 40 seconds on the dev environment and it
is quite long.

Haml and Sass shouldn't be having that effect. Look elsewhere for your
problems.

The fact that you're asking this makes me think that you want *page*
caching, not controller caching.

Best,

Jian Lin wrote:

At work, we have a situation where when

script/server

is run, then all the controller code is cached. This is to speed up the
development server. But that will mean that whenever we change the
controller code, we need to restart the server.

Yes, that's normal behavior in development mode.

I thought that was the normal behaviour in production mode, not development.

Colin

Colin Law wrote:

Jian Lin wrote:

At work, we have a situation where when

� script/server

is run, then all the controller code is cached. �This is to speed up the
development server. �But that will mean that whenever we change the
controller code, we need to restart the server.

Yes, that's normal behavior in development mode.

I thought that was the normal behaviour in production mode, not
development.

Right you are. I didn't write the word I meant to write. :stuck_out_tongue:

Colin

Best,

Marnen Laibow-Koser wrote:

  foo.js?1273424325

which is to use the cached version as long as there is no code change,
but recompile it when there is code change?

Because it's a different kind of caching. JavaScript caching simply
involves using the browser cache for included files, whereas controller
caching involves Ruby objects in memory on the server.

I know that they are different kind of caching, -- now can't the same
principle be used? When newer, reload / recompile it -- when older, no
need to reload or recompile.

so when the controller code in cache is newer, then no need to
re-compile. when it finds that the controller code is newer, then
recompile it.

by the way, what is this caching? I thought it is re-interpreted each
time? So what is the caching for -- it is not byte code like in Python?

Marnen Laibow-Koser wrote:
>> foo.js?1273424325

>> which is to use the cached version as long as there is no code change,
>> but recompile it when there is code change?

> Because it's a different kind of caching. JavaScript caching simply
> involves using the browser cache for included files, whereas controller
> caching involves Ruby objects in memory on the server.

I know that they are different kind of caching, -- now can't the same
principle be used? When newer, reload / recompile it -- when older, no
need to reload or recompile.

so when the controller code in cache is newer, then no need to
re-compile. when it finds that the controller code is newer, then
recompile it.

by the way, what is this caching? I thought it is re-interpreted each
time? So what is the caching for -- it is not byte code like in Python?

Caching is sort of the wrong word, because it implies that rails does
something in order to achieve caching, whereas the opposite is true:
rails' code reloading is the extra behaviour.
There have been attempts to make the code reloading stuff only reload
what needs to be reloaded, see for example http://github.com/thedarkone/rails-dev-boost

Fred