You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to cache queries on the most frequently accessed page on my site. I'm getting an error when adding Rails.cache. The page loads fine without caching.
error
can't dump anonymous class #<Module:0x00007fc4d5b52ba0>
dashboard_controller.rb
defnews_feed_itemsRails.cache.fetch("news_feed_items_#{filter_as_json}_#{items_page}",expires_in: 1.hour)doPgSearch.multisearch(current_user_states.join(' ')).where('updated_at >= ?',number_of_days.days.ago).order(:updated_at).page(items_page).per(5)end# TODO: Add a filter sort by popularityend
The text was updated successfully, but these errors were encountered:
I'm guessing that it's not possible to cache an instance of ActiveRecord::Relation, which is what PgSearch.multisearch returns. In any case, caching a Relation before it has loaded would mean caching the object that represents the query, but not caching its results, which would be of little value.
I would try chaining #to_a to the end of the relation to get back an array of records. Presumably then those records could be cached.
I'm trying to cache queries on the most frequently accessed page on my site. I'm getting an error when adding
Rails.cache
. The page loads fine without caching.error
dashboard_controller.rb
The text was updated successfully, but these errors were encountered: