query results caching - storing

26 views
Skip to first unread message

kosfar

unread,
May 21, 2012, 5:47:59 AM5/21/12
to ActiveScaffold : Ruby on Rails plugin
Hello guys,

I am new to caching in Rails and so far I have not found a solution
for caching heavy database query results that apply to data that do
not change very often and are executed inside the Active Scaffold
framework.

I read everywhere for caching through this "ClassName.method_name(…)",
thus calling a method, fetching the results and put them in Cache. But
in simple Active Scaffold controllers, there is no call to methods,
just
active_scaffold :ClassName do |config|
...
end

So my question, what is the workflow to enable caching of database
queries in the Active Scaffold way? Do I have to hack Active Scaffold
source files?

thanx a lot in advance!

ser...@entrecables.com

unread,
May 21, 2012, 4:34:40 PM5/21/12
to actives...@googlegroups.com
On Mon, 21 May 2012 02:47:59 -0700 (PDT), kosfar <dant...@gmail.com>
wrote:
If you are going to put cache in the model, ActiveScaffold will use
model methods to query, so you don't need to hack ActiveScaffold source.
Maybe you will have to read the code to know the methods used by
ActiveScaffold, although it use the usual methods in rails to query.

You should never modify ActiveScaffold source, you can override
controller methods defined by ActiveScaffold, and you can use super to
invoke ActiveScaffold method.

For example, overriding the do_list method:
def do_list
if cached
return cached
else
super
end
end

Also, maybe it works using cache_page or cache_action in the
controller:
http://guides.rubyonrails.org/caching_with_rails.html

Anyway, you shouldn't do premature optimization and cache at the
beginning, you should add caches when you find requests are slow.
Reply all
Reply to author
Forward
0 new messages