Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

cache_digests #378

Closed
kidpollo opened this Issue · 13 comments

6 participants

@kidpollo

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

@databyte
Collaborator

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.

@ngan

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:

rabl/watever//json

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.

@siong1987

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}/"
        end

        expanded_cache_key << retrieve_cache_key(key)
        expanded_cache_key
      end

ref: https://github.com/rails/rails/blob/master/activesupport/lib/active_support/cache.rb#L82

@siong1987

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

@nesquena
Owner

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

@nesquena nesquena closed this
@tispratik

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

@tispratik

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]/
@nesquena
Owner

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

@tispratik

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?

@siong1987

@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
@siong1987

@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.

@tispratik
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.