Jets supports caching. It currently supports Fragment Caching.


In the view you can use the cache helper.

<% @products.each do |product| %>
  <% cache product do %>
    <%= render product %>
  <% end %>
<% end %>

It’ll generate a cache key that looks like


The random string is a digested hash of the contents of the product partial. So when you change the view code, the cache is invalidate automatically.


To enable caching:


Jets.application.configure do
  config.controller.perform_caching = true
  config.cache_store = :memory_store

Cache Stores

Jets caching is based on the Rails caching code, hence they work very similar. Here are examples of the different cache stores. They are all the same ones Rails support.


Jets.configure do |config|
  # config.cache_store = :memory_store,  size: 64.megabytes
  # config.cache_store = :file_store, "/path/to/cache/directory"
  config.cache_store = :mem_cache_store, ""
  # config.cache_store = :redis_cache_store, { url: ENV['REDIS_URL'] }
  # config.cache_store = :null_store

Since Jets runs on AWS Lambda, some of them do not really make sense to use: memory_store and file_store.

If you’re using mem_cache_store or redis_cache_store with AWS ElastiCache, then your Lambda functions need to be in a private subnet in a VPC. See: VPC.

The Rails Guide Caching documentation is also useful: