Socket
Book a DemoInstallSign in
Socket

cache_replace

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cache_replace

0.1.3
bundlerRubygems
Version published
Maintainers
1
Created
Source

Gem Version Build Status Coverage Status Code Climate

Rails rendering extension for more server-side html caching

Why do I need this?

To improve fragment caching efficiency in Rails by only caching the things that change. Use this gem after you have configured as much in-memory caching as possible using standard techniques such as Russian Doll caching.

Install

Add this line to your Gemfile:

gem 'cache_replace'

Add this line to a helper file, likely your ApplicationHelper:

include CacheReplace

Use

This gem allows you to easily cache a partial of static html and replace inner dynamic html. Here is an example scenario:

You have some html that would be cached, except for some uncacheable code nested in the DOM. For example:

file.html.haml:
= render 'container'
_container.html.haml:
.lots
  .of
    .htmls
      = render 'dynamic'
_dynamic.html.haml:
= complicated_uncacheable_stuff

In the scenario above, you can't cache anything without resorting to madness. With cache_replace, you can:

file.html.haml:
= render_cached 'container', replace: 'dynamic'
_container.html.haml:
- cache "container" do
  .lots
    .of
      .htmls
        = cache_replace_key 'dynamic'
_dynamic.html.haml:
= complicated_uncacheable_stuff

In the above example, you could also remove the _dynamic.html.haml file like so:

file.html.haml:
= render_cached 'container', replace: {dynamic: complicated_uncacheable_stuff}

Options

render_cached provides 4 calling styles:

Single partial to replace

render_cached "container", replace: "inner"

Array of partials to replace

render_cached "container", replace: ["inner"]

Map of keys to replace with values

render_cached "container", replace: {key_name: a_helper_method(object)}

Yield to a hash of keys to replace with values

render_cached "container" do
  {key_name: a_helper_method(object)}
end

Contribute

  • Fork it
  • Create your feature branch (git checkout -b my-new-feature)
  • Commit your changes (git commit -am 'Add some feature')
  • Push to the branch (git push origin my-new-feature)
  • Create new Pull Request

FAQs

Package last updated on 25 Aug 2013

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.