Skip to content


Subversion checkout URL

You can clone with
Download ZIP


cache_digests #378

kidpollo opened this Issue · 13 comments

6 participants


If I include cache_digests gem in my project will it work with rabl?


You'll have to try it out and tell us. Most likely not since Rabl != Rails. We use ActiveSupport's fragment caching to do the actual cache_key lookup but not much else. The way the templates are stored internally is not the same as ActionView so it's not the same setup.

Poke around, play with it - make it do what you want and submit a pull request. If you have larger changes in mind, it may be more helpful to create an Issue highlighting the problem and your proposed solution to make sure it'll get merged in with feedback.


It looks it it "works". However, cache_digest actually adds a digest of the contents in the cache do block. With RABL, that digest will be missing:


Notice the //. I think the digest is suppose to go in the middle of that...

What this boils down to is that you need to go back to the old school "v1", "v2", etc notation.


Rabl uses expand_cache_key for caching.

So, the easier way to version your cache is to actually use environment variables like "RAILS_CACHE_ID" or "RAILS_APP_VERSION".

      def expand_cache_key(key, namespace = nil)
        expanded_cache_key = namespace ? "#{namespace}/" : ""

        if prefix = ENV["RAILS_CACHE_ID"] || ENV["RAILS_APP_VERSION"]
          expanded_cache_key << "#{prefix}/"

        expanded_cache_key << retrieve_cache_key(key)



In fact, cache_digests is possible with minor modification on #447.


Part of 0.9.0.pre now, let me know if you run into any problems thanks to @siong1987

@nesquena nesquena closed this

Thanks @nesquena, do we need to include the cache-digests gem to avail this new feature?


Looks like this has not been enabled for rails3. If we include the cache_digests gem it should be enabled i believe.

  require 'rabl/tracker'  if Rails.version =~ /^[4]/
  require 'rabl/digestor' if Rails.version =~ /^[4]/

Can you submit a patch? I'll add in support.


Thanks for the support @nesquena . I looked at problem. Here are my findings: rabl gem currently depends on builder 3.2.2 and cache_digests gem depends on builder 3.0.0. If i try to downgrade rabl to builder 3.0.0, it complains about depending on rack 1.5.2 vs rack 1.4.0 if i were to downgrade builder. Once we resolve the dependency problems, then we can use cache_digests.

Currently rabl has reference to ActionView::Digester (which is a Rails4 class), we will need to change it to use cache_digests somehow.

Comments/Suggestions/Path Forward?


@tispratik @nesquena not sure it is a good idea to support cache_digests in this case. the idea is that this will work with rails 4 without any outside gem. but, for rails 3, an outside gem is required in order to make this work which is not ideal(more complexity to the code base too).


@tispratik it is. it supports rails 4. cache_digests isn't supported in rails 3 and that's why i didn't add rails 3 support for this feature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.