ActiveRecord query caching is enabled when a controller’s action is invoked. I also know that you can do something like this to temporarily enable caching for a given Model for a given code block:
User.cache do .... end
But is there a way to enable query caching for other contexts (e.g. when a script is run under the rails environment using ./script/runner)?
An ActiveRecord query cache lives only for the duration of a particular action (i.e. request). If you want a cached object to survive longer or be used between processes you need to look at something like memcached.