My current homepage displays all available categories and all of the number of posts each category has. This of course is having a performance hit on the website and i was just wondering if this could be cached at all?
I don't mind if the cache is a little out of date and if the number of posts isn't 100% accurate at every refresh, but i would like it to only make the query every 30 minutes or so.
In Rails you can cache pretty much everything.
You can cache partials or queries. And you can expire them manually too.
For example
cache('categorylist') do
render partial: 'such'
end
And in the post.rb
model, after each create of post, reset this and force it to evaluate on next run
after_create {
Rails.cache.delete('categorylist')
}
This way, your partial will only be evaluated (and written to cache) when a new post has been created. All other times, it will be fetched from cache.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With