Cache in Web Applications

“Cache” in database field

For Markdown, you can render and store in another field.

field :body
field :body_html

Markdown files could be very big, store them in Redis/Memcache may not be a good idea because cache store we do not expect them to persist. You can compute the rendered result into another column (body_html).

Fragment Cache

- cache post do
  ...

Cache Query at your Cache Store

def expensive
  Rails.cache.fetch(cache_key, expires_in: 12.hours) do
    # expensive query happens here!
  end
end

ETag

fresh_when
expires_in

CDN

For your static assets (images, svg). Use Fastly!