M
M
M1Anderson2015-03-21 18:07:43
Ruby on Rails
M1Anderson, 2015-03-21 18:07:43

Is this caching correct in Rails?

I'm trying to cache through the standard gem - cache_digest, but the application still creates queries to the database:

- cache @bgroups do
            - @bgroups.each do |bgroup|
              .bgroup
                = link_to bgroup.name, bgroup_vacancy_path(bgroup)

Console:
Bgroup Load (0.3ms) SELECT "bgroups".* FROM "bgroups" LIMIT 20
Cache digest for app/views/home/index.html.haml: f62c6ca48d18920cf265aa17882d6e1a
Read fragment views/bgroups/1/bgroups/2/bgroups/3/ bgroups/4/bgroups/5/bgroups/6/bgroups/7/bgroups/8/bgroups/9/bgroups/10/bgroups/11/bgroups/12/bgroups/13/bgroups/14/bgroups/15/bgroups/ 16/bgroups/17/bgroups/18/bgroups/19/bgroups/20/f62c6ca48d18920cf265aa17882d6e1a (0.0ms)

As far as I understand, there should not be a request to the database at all if the information in the database has not changed, otherwise what is the point of such caching? What is the error then?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
vsuhachev, 2015-03-22
@M1Anderson

1) you need to cache an object that has an updated_at method
2) caching is usually turned off in the development environment

- @bgroups.each do |bgroup|
  = cache bgroup do
    .bgroup
       = link_to bgroup.name, bgroup_vacancy_path(bgroup)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question