cache_digests #378

Closed
kidpollo opened this Issue Dec 20, 2012 · 13 comments

Comments

Projects
None yet
6 participants
@kidpollo

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

@databyte

This comment has been minimized.

Show comment Hide comment
@databyte

databyte Dec 20, 2012

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.

Collaborator

databyte commented Dec 20, 2012

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

This comment has been minimized.

Show comment Hide comment
@ngan

ngan Jan 24, 2013

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.

ngan commented Jan 24, 2013

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

This comment has been minimized.

Show comment Hide comment
@siong1987

siong1987 May 4, 2013

Contributor

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

Contributor

siong1987 commented May 4, 2013

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

This comment has been minimized.

Show comment Hide comment
@siong1987

siong1987 May 4, 2013

Contributor

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

Contributor

siong1987 commented May 4, 2013

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

@nesquena

This comment has been minimized.

Show comment Hide comment
@nesquena

nesquena Sep 3, 2013

Owner

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

Owner

nesquena commented Sep 3, 2013

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

@nesquena nesquena closed this Sep 3, 2013

@tispratik

This comment has been minimized.

Show comment Hide comment
@tispratik

tispratik Feb 12, 2014

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

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

@tispratik

This comment has been minimized.

Show comment Hide comment
@tispratik

tispratik Feb 12, 2014

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]/

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

This comment has been minimized.

Show comment Hide comment
@nesquena

nesquena Feb 12, 2014

Owner

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

Owner

nesquena commented Feb 12, 2014

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

@tispratik

This comment has been minimized.

Show comment Hide comment
@tispratik

tispratik Feb 12, 2014

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?

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

This comment has been minimized.

Show comment Hide comment
@siong1987

siong1987 Feb 13, 2014

Contributor

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

Contributor

siong1987 commented Feb 13, 2014

@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

This comment has been minimized.

Show comment Hide comment
@tispratik

tispratik Feb 14, 2014

Thanks for your quick response Siong. I wish rabl used the standard api to
render partials so that i could automatically use the goodness that rails
introduced in every new release.

~Pratik

On Wed, Feb 12, 2014 at 5:21 PM, Siong notifications@github.com wrote:

@tispratik https://github.com/tispratik @nesquenahttps://github.com/nesquenanot 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.

Reply to this email directly or view it on GitHubhttps://github.com/nesquena/rabl/issues/378#issuecomment-34938962
.

Thanks for your quick response Siong. I wish rabl used the standard api to
render partials so that i could automatically use the goodness that rails
introduced in every new release.

~Pratik

On Wed, Feb 12, 2014 at 5:21 PM, Siong notifications@github.com wrote:

@tispratik https://github.com/tispratik @nesquenahttps://github.com/nesquenanot 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.

Reply to this email directly or view it on GitHubhttps://github.com/nesquena/rabl/issues/378#issuecomment-34938962
.

@siong1987

This comment has been minimized.

Show comment Hide comment
@siong1987

siong1987 Feb 15, 2014

Contributor

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

Contributor

siong1987 commented Feb 15, 2014

@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

This comment has been minimized.

Show comment Hide comment
@tispratik

tispratik Feb 15, 2014

I rewrote my template using jbuilder and it works fine with cache_digests
in rails3. So, i think there is some compat issue of rabl with
cache_digests.

On Fri, Feb 14, 2014 at 7:11 PM, Siong notifications@github.com wrote:

@tispratik https://github.com/tispratik it is. it supports rails 4.
cache_digest isn't supported in rails 3 and that's why i didn't add rails
3 support for this feature.

Reply to this email directly or view it on GitHubhttps://github.com/nesquena/rabl/issues/378#issuecomment-35145986
.

I rewrote my template using jbuilder and it works fine with cache_digests
in rails3. So, i think there is some compat issue of rabl with
cache_digests.

On Fri, Feb 14, 2014 at 7:11 PM, Siong notifications@github.com wrote:

@tispratik https://github.com/tispratik it is. it supports rails 4.
cache_digest isn't supported in rails 3 and that's why i didn't add rails
3 support for this feature.

Reply to this email directly or view it on GitHubhttps://github.com/nesquena/rabl/issues/378#issuecomment-35145986
.

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