Skip to content

private cache_path passed in as a symbol doesn't work in v1.2.0 #55

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
MarinaMurashev opened this issue Nov 16, 2017 · 1 comment
Open

Comments

@MarinaMurashev
Copy link

MarinaMurashev commented Nov 16, 2017

I'm running Rails 4.2.9 and Ruby 2.3.5. I just upgraded actionpack-action_caching gem from 1.1.1 to 1.2.0. Before, on v1.1.1 I was able to specify the cache_path with a symbolized method name (without the _url postfix), like this:

class MyController < ApplicationController
  caches_action :my_action, cache_path: :my_cache_path, if: :is_cacheable?

  def my_action
    ...
  end

  private

  def my_cache_path_url
    url_for(
      only_path: true, 
      action: "my_action", 
      format: "json", 
      page_number: params[:page],
      max_updated_at: MyModel.maximum(:updated_at).to_i,
    )
  end

  def is_cacheable?
    true
  end
end

After updating the gem to v1.2.0, this would only work if I wrapped the cache_path method in a new Proc with its full name including the _url portion:

caches_action :my_action, cache_path: Proc.new { my_cache_path_url }, if: :is_cacheable? # works

It also works with the short lambda syntax:

caches_action :my_action, cache_path: -> { my_cache_path_url }, if: :is_cacheable? # works

Can you verify whether v1.2.0 of the gem hurt the ability to pass in a symbolized url path name to cache_path?:

 caches_action :my_action, cache_path: :my_cache_path, if: :is_cacheable? # does not currently work
@MarinaMurashev
Copy link
Author

MarinaMurashev commented Nov 17, 2017

UPDATE:

I tried moving my path method under protected instead of private and now its symbol version does work, with the _url postfix added on:

class MyController < ApplicationController
  caches_action :my_action, cache_path: :my_cache_path_url, if: :is_cacheable? # works

  def my_action
    ...
  end

  protected

  def my_cache_path_url
    url_for(
      only_path: true, 
      action: "my_action", 
      format: "json", 
      page_number: params[:page],
      max_updated_at: MyModel.maximum(:updated_at).to_i,
    )
  end

  private

  def is_cacheable?
    true
  end
end

If this is expected behavior, please make that more explicit in the readme -- that the symbolized cache path needs to be under protected and cannot be under private.

@MarinaMurashev MarinaMurashev changed the title cache_path passed in as a symbol doesn't work in v1.2.0 private cache_path passed in as a symbol doesn't work in v1.2.0 Nov 17, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant