Skip to content

Instantly share code, notes, and snippets.

@kattak
Created January 16, 2017 07:06
Show Gist options
  • Save kattak/2aa6e0d935b11d97ec72879a6a54be6f to your computer and use it in GitHub Desktop.
Save kattak/2aa6e0d935b11d97ec72879a6a54be6f to your computer and use it in GitHub Desktop.
In progress...

##Built-in Rails/Gems

[0] Rails guide to caching in rails - read this first http://guides.rubyonrails.org/caching_with_rails.html

Heroku Guide to Caching Strategies for Rails - read this second https://devcenter.heroku.com/articles/caching-strategies

[1] Countercache in ActiveAssocation http://yerb.net/blog/2014/03/13/three-easy-steps-to-using-counter-caches-in-rails/

But only for aggregate values Upgrade to regular AR counter-caching https://github.com/magnusvk/counter_culture

[2] HTTP Caching

https://developers.google.com/web/fundamentals/performance/optimizing-content-efficiency/http-caching "each server response provides the correct HTTP header directives to instruct the browser on when and for how long the browser can cache the response."

Heroku guide to implement: https://devcenter.heroku.com/articles/http-caching-ruby-rails Good news: already basically/simply enabled in Rails 3+ Why would use this gem instead of Rails default? https://github.com/rtomayko/rack-cache hmmm

NOOP: In computer science, a NOP or NOOP (short for No Operation) is an assembly language instruction, programming language statement, or computer protocol command that does nothing.

[3]"blob level caching plugged into ActiveRecord" https://github.com/Shopify/identity_cache

What does this mean?

Fetch the images for the Product. Images are embedded so the product fetch would have already loaded them.

@images = @product.fetch_images

this looks nice

class Product < ActiveRecord::Base
  include IdentityCache
  has_many  :images
  has_one   :featured_image

  cache_has_many :images
  cache_has_one :featured_image
end

@product.fetch_featured_image
@product.fetch_images

can cache just attributes as well

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment