Pregunta

I know dalli (caching) is pretty useful to enhance performance for static sites.
But what about dynamic sites, which are updated quite often?
What is the correct way to set up dalli?

One problem I've encountered for example: dalli recognizes different params[:page] as the same page when using pagination:(

How would you guys design the system when using dalli for both

  • the page that gets updated so often
  • the page that won't be updated so often

My current code is just like this. That's why I'm facing the pagination problem when using caching...

controller

caches_page :index, :show

config/environments/development.rb

config.consider_all_requests_local       = true
config.action_controller.perform_caching = true
config.cache_store = :dalli_store
¿Fue útil?

Solución

I had the same problem and decided that fragment caching in the views was a better option.

The cache keys for the fragments are based on the models and will change every time a model is updated.

Here is an extract from one of my views in haml.

 - @content_pages.each do |content_page|
          - cache(content_page.get_cache_key('home_page_content_page')) do
            ...Render ContentPage model

It is based on an approach recommended by 37Signals here How key-based cache expiration works

I have a full write up of the approach on my website here

Rails caching strategy using key-based approach

Hope this helps

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top